Monday, April 11, 2011

Get Associated Entity Code On Dynamics CRM Form

Custom entities created within Dynamics CRM will have different entity code while imported to different Organisations. It is difficult to define the entity code while the deployment is moved from development to testing/UAT and production. Certain cases deployment will be done by the release team who will just follow the instructions rather it would not be easy for them to edit the script file to update the custom entity code.

It is tricky to get this, but the below function will return the entity code on the Form. Make sure the associated entity link is not hidden from the form and will be hidden if required using javascript after getting the entity code.

// ----------------------------------------------------------

// getObjectTypeCode

// This function will return Object type Code from url

function getObjectTypeCode(name, url) {

name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");

var regexS = "[\\?&]" + name + "=([^&#]*)";

var regex = new RegExp(regexS);

var results = regex.exec(url);

if (results == null)

return "";


return results[1];


/********************END - getObjectTypeCode function**********/

The following method accepts the name of the

// ----------------------------------------------------------

// getEntityCode

// This function will return Entity Object type Code

function getEntityCode(name) {

//Get Entity url

var navEntity = document.getElementById(name);

if (navEntity != null) {

var img = navEntity.getElementsByTagName("IMG")[0];

//get Entity Object Type Code

var objectTypeCode = getObjectTypeCode('objectTypeCode', img.src); = "none";

if (objectTypeCode != "")

return objectTypeCode;


return "";


return "";


/********************END - getEntityCode function**********/

No comments: