1

Recently lookup field in dynamic CRM form started throwing this error:

"Unable to get property '0' of undefined or null reference"

when we tried to change this lookup field. There is no Javascript called on Onchange event I have attached a screenshot of the error:

Click to see Error

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Hussain Ahmad
  • 71
  • 1
  • 9
  • 2
    I think you have dynamically attached Change event to `productid`. Can you show your code, so that we can optimize it not to throw error. I think your function name is `setadditionalparams`. – Dot_NET Pro Mar 04 '16 at 05:18
  • i haven't attached any function or javascript to onchange event of the lookup field.The thing confusing me is that there is no fucntion named as setadditionalparams. – Hussain Ahmad Mar 04 '16 at 16:59

1 Answers1

0

In this case, if I did not know where this setaddionalparams function is located, my first move would be to disable all (or one by one) custom events on the form in the Handler Properties dialog that is called when you double click on the event handler in the Form Properties dialog in the Events tab (this one).
If the error stops appearing then obviously the function is somewhere in your code.
Good luck!

UPDATE

There can be more reasons why you still see this error, please check scripts attached to the Ribbon, scripts inside HTML Web Resources and IFrames if you have any.
In addition, it may not be a direct call to the attribute by name, it may be a for loop that iterates through all attributes in the form. In this case you will need to search the code by the following keyword getValue()[0]. It seems like someone accesses a lookup attribute without checking if it's null. It should be fixed like this:

var productId = null;    
var lookupValue = Xrm.Page.getAttribute("productid").getValue();
if (!!lookupValue && lookupValue.length > 0){
    productId = lookupValue[0].id;
}
Alex
  • 211
  • 2
  • 12
  • I have disabled all the events already but still when i add a new product to opportunitiy by hitting the search button right to the productid field in opporuntiy product form i get this error message in a JS dialog There was an Error in this field customized event . Field : productid Event : setadditionalparams Error: Unable to get property '0' of undefined or null reference – Hussain Ahmad Mar 07 '16 at 17:54
  • My best guess is that someone tries to get a value of the lookup attribute `productid` without checking if there is any value, like this: `Xrm.Page.getAttribute("productid").getValue()[0].id`. This is not correct, first the value should be checked if it's `NULL` and then accessed by `[0]`. Is there any loop that goes through all attributes in the form? Do you have a script attached to Ribbon? If yes, then you will need to check that one too. – Alex Mar 07 '16 at 18:02
  • Also do you have any HTML Web Resource on the form? Or any IFrame? Maybe the script tries to manipulate with the form from there... – Alex Mar 07 '16 at 18:06
  • i had a web resourece attached on the form but i have removed all the web resources and custom Javascripts that are present on the opportunity product form. Still the issues remain the same. – Hussain Ahmad Mar 07 '16 at 18:30
  • No field is trying to get value of the productid lookup field. The error shows whenever we click on productid lookup field but after i close the error dialog by hitting the ok button i can pick a product out of the list. They seems no problem here, but the error message is annoying. – Hussain Ahmad Mar 07 '16 at 18:32
  • Yeah, it's annoying and It's hard to tell what's wrong when I do not see the code and I do not have any advice left for now. I hope you will resolve this issue soon. – Alex Mar 07 '16 at 18:45