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....

No comments:

Post a Comment