locked
Unable to get property '0' of undefined or null reference. RRS feed

  • Question

  •  Hi,

    I have a nice working OnChange script event on a lookup field. It works fine in both of my test and prod environments.

     

    Recently it started throwing this error "Unable to get property '0' of undefined or null reference" when one of the user tried to change this lookup field differently.

     

    Instead of entering the data into the field and pressing enter or selecting the lookup to choose one of the values, user clicked tab after entering data so that he can enter data quickly.

     

    But since it is a tab click my script is picking the lookup field value as 'null' and throwing this script error with a dialog box.(That is what I understood)

     

    There was an error with this field's customized event.

    Field:new_priority

    Event:onchange

    Error:Unable to get property '0' of undefined or null reference.

     

    Interesting enough, the error is in test environment too but it does not pop up a dialog box and it is working fine unless I debug the page, I didn't knew the error was in there.

     

    But in production, it is popping the error with a dialog box.

     

    Can you please let me know how to proceed or what to look for.

     

    Note: On debug I found the error on this line:

     

     var priority=Xrm.Page.data.entity.attributes.get("new_priority").getValue()[0].name;

    Thanks

    Friday, October 17, 2014 8:48 PM

Answers

  • It looks like there is no value in the new_priority field, and you are not trapping this. Try something like:

    var priorityValue = Xrm.Page.data.entity.attributes.get("new_priority").getValue();
    if (priorityValue != null && priorityValue.length > 0)
    {
     var priority = priorityValue[0].name;
    }

     

    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    • Proposed as answer by Mohd Saad Monday, October 20, 2014 5:15 AM
    • Marked as answer by ReignFan Monday, October 20, 2014 6:15 PM
    Friday, October 17, 2014 9:37 PM
    Moderator

All replies

  • It looks like there is no value in the new_priority field, and you are not trapping this. Try something like:

    var priorityValue = Xrm.Page.data.entity.attributes.get("new_priority").getValue();
    if (priorityValue != null && priorityValue.length > 0)
    {
     var priority = priorityValue[0].name;
    }

     

    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    • Proposed as answer by Mohd Saad Monday, October 20, 2014 5:15 AM
    • Marked as answer by ReignFan Monday, October 20, 2014 6:15 PM
    Friday, October 17, 2014 9:37 PM
    Moderator
  • Thank you. It worked.
    Monday, October 20, 2014 6:15 PM