locked
Calculations in CRM 2011 RRS feed

  • Question

  • Hi,

    I have a field on the case entity where estimate values are entered as a floating point number (new_estimateto) then the user selects whether this value is in minutes, hours, days or weeks from another field (new_eft).

    I now need to convert this estimate into hours so that I can perform so other calculations on the case entity so I have created a field (new_estinhours) which is also a floating point number and I was hoping to run some jscript on change / load of the form which calculates this in hours.

    I keep getting an error - Cannot assign to a function result

    can anyone help with this -- could be a silly error as I am relatively new to CRM

    function estconvert()
    {
    if (Xrm.Page.getAttribute("new_eft").getValue() = "100000000")
    // Minutes
    {
    //get minutes field value
    var mins = Xrm.Page.getAttribute("new_estimateto").getValue();
    // Perform the calculation
    var minshours= mins.getValue() / 60;
    // Set the destination field's value to the new value
    new_estinhours.setValue(minshours);
    }
    else
    if (Xrm.Page.getAttribute("new_eft").getValue() = "100000003")
    //days
    {
    //get day field value
    var days= Xrm.Page.getAttribute("new_estimateto").getValue();
    // Perform the calculation
    var dayshours= days.getValue() * 8;
    // Set the destination field's value to the new value
    new_estinhours.setValue(dayshours);
    }
    else
    if (Xrm.Page.getAttribute("new_eft").getValue() = "100000002")
    //weeks
    {
    //get weeks field value
    var weeks= Xrm.Page.getAttribute("new_estimateto").getValue();
    // Perform the calculation
    var wkshours= (weeks.getValue() * 5) * 8;
    // Set the destination field's value to the new value
    new_estimateinhours.setValue(wkshours);
    }
    else
    if (Xrm.Page.getAttribute("new_eft").getValue() = "100000001")
    // hours
    {
    // set field same as estimate to
    var hours= Xrm.Page.getAttribute("new_estimateto").getValue();
    new_estinhours.setValue("new_estimateto");
    }
    else
    if (Xrm.Page.getAttribute("new_eft").getValue() == null ) 
    // no value entered
    {
    var hours = Xrm.Page.getAttribute("new_estimateto").getValue();
    new_estinhours.setValue("new_estimateto");
    }
    }


    • Edited by Cherie77 Thursday, June 13, 2013 10:47 PM
    Thursday, June 13, 2013 10:46 PM

Answers

  • Hi Cherie,

    In the script, in the "IF" condition you r trying to assign value instead of comparing with the value.

    if (Xrm.Page.getAttribute("new_eft").getValue() = XXXX)

    must be replaced with

    if (Xrm.Page.getAttribute("new_eft").getValue() == XXXX)


    • Proposed as answer by Rakesh.N Friday, June 14, 2013 5:39 AM
    • Marked as answer by Cherie77 Friday, June 14, 2013 8:05 AM
    Friday, June 14, 2013 5:39 AM

All replies

  • Hi Cherie,

    In the script, in the "IF" condition you r trying to assign value instead of comparing with the value.

    if (Xrm.Page.getAttribute("new_eft").getValue() = XXXX)

    must be replaced with

    if (Xrm.Page.getAttribute("new_eft").getValue() == XXXX)


    • Proposed as answer by Rakesh.N Friday, June 14, 2013 5:39 AM
    • Marked as answer by Cherie77 Friday, June 14, 2013 8:05 AM
    Friday, June 14, 2013 5:39 AM
  • whoops that was a silly oversight - thanks
    Friday, June 14, 2013 8:05 AM