Showing posts with label Xrm. Show all posts
Showing posts with label Xrm. Show all posts

Tuesday, August 23, 2016

Dynamic CRM - Unable to get property 'value' of undefined or null reference.



In this post, I would like to talk about this error while executing a Fetch Xml through Xrm Service Toolkit (JavaScript).

There was an error with this field's customized event.
Field: window
Event: onload
Error: Unable to get property 'value' of undefined or null reference.

The script where the error occured is :

var resultset = XrmServiceToolkit.Soap.Fetch(strFetchXml);

Generally with the research it involved, I found various possibilities that could result in this error message (mainly being missing field in a given form / entity), but that was not the case for me. 

 After spending huge amount of time, it was found that the resultset after executing Fetch XML was null and this error message was part of Xrm Service Toolkit for handling returned data. 

To make it more clear, I added a try / catch for the above statement and added a not null condition for resultset.

if(resultset != null)
{
}

Above implemented action(s) made sure, it didn't throw any error messages and handled properly.

Happy coding....

Friday, August 19, 2016

XRM Page - getId() returning null or empty string

In this blog, I would like to indicate the usage of Xrm.Page.data.entity.getId() and its responses in various CRM versions and how it affects. Also what we can do to handle appropriately without having exceptions.

The return value for Xrm.Page.data.entity.getId() will return NULL, when called from a Create form (specific to Dynamics CRM version 2011)

The return value for Xrm.Page.data.entity.getId() will return EMPTY STRING, when called from a Create form (specific to Dynamics CRM version 2013).

To handle this given situation in any version (2011,2013 or 2015), you could implement the following code:


 var FormType = Xrm.Page.ui.getFormType();
 if(FormType != 1) //Refers to update form or other Form statuses.
  {
     var myId = Xrm.Page.data.entity.getId();
  }

Happy coding....