none
Code is returning error Object is null or undefined when the value exists

    Question

  • When I attempt to run my code I get an error that the value is null or undefined. However, the alert line returns the correct value of the field I'm looking up. I have debugged the code and the var ratePercentage remained undefined, but the line before that correctly pops up a message box with the value of the field. What am I doing wrong? I've tried several different variations of code to get the value there but all return null or undefined?

    Thanks for any help.

    <Message>Unable to get value of the property 'new_CommissionRate': object is null or undefined</Message>
       <Line>25</Line>

    var _rate = this.parent.JSON.parse(_retrieve.responseText).d;
                alert(_rate.new_CommissionRate);
                var ratePercentage = _rate.result.new_CommissionRate.getValue();
                Xrm.Page.getAttribute("new_commissionpercentage").setValue(ratePercentage);
                Xrm.Page.getAttribute("new_commissionpercentage").setSubmitMode("always");   

    Wednesday, August 28, 2013 6:59 PM

Answers

  • Hi,

    If the value of _rate.new_CommissionRate is correct other than the fact that is is text, then just convert to to a decimal using parseFloat when you set the value of the attribute:

    var ratePercentage = parseFloat(_rate.new_CommissionRate);


    Michael Palmer
    xRMPalmer     @MJFPalmer     Rockstar365

    Wednesday, August 28, 2013 7:25 PM

All replies

  • if the alert gives you the correct value just assign that value to the ratePercentage variable

    alert(_rate.new_CommissionRate);
    var ratePercentage = _rate.new_CommissionRate;

    don't need to use getValue, it's not a field.


    My blog: www.crmanswers.net


    Wednesday, August 28, 2013 7:08 PM
  • I had tried that but receive an error that the control only accepts numbers or null as an input. I did just notice though that when debugging it the value is input as a string rather than a numeric value. The field on both records is a decimal.  I'm wondering if
    _retrieve.responseText
    is the issue now?
    Wednesday, August 28, 2013 7:20 PM
  • Hi,

    If the value of _rate.new_CommissionRate is correct other than the fact that is is text, then just convert to to a decimal using parseFloat when you set the value of the attribute:

    var ratePercentage = parseFloat(_rate.new_CommissionRate);


    Michael Palmer
    xRMPalmer     @MJFPalmer     Rockstar365

    Wednesday, August 28, 2013 7:25 PM
  • Thank you so much!!! that did it.
    Wednesday, August 28, 2013 7:37 PM