Archive

Posts Tagged ‘Object Type Codes’

How to get Object Type Codes of Entities in CRM 2011

September 8, 2011 3 comments

Hi,

In this article i have explained different ways to fetch entities “Object Type Code”

  •  Using SQL Query :-

Get Object Type codes by Sql Query

Query>

SELECT ObjectTypeCode,*

FROM

ENTITYVIEW

Using JScript  :-

  • The “ObjectTypeCode” can be extracted from Query String using JScript
  • “ObjectTypeCode” resides in “etc” query string  parameter
  • Below is the JScript statement to get “ObjectTypeCode”

var currEntityObjTypeCode= Xrm.Page.context.getQueryStringParameters().etc

Key Points

  • Type codes below 10,000 are reserved for OOB entities.
  • Custom entities have a value greater than or equal to 10,000.

Note:- Custom entity object type codes may change during import and are not guaranteed to be the same between systems.

Getting Object Type Code by ‘Entity Name’ using Jscript

Below script uses CRM inbuilt logic and return the entity type code (or) object type code for the given entity name.

function getObjectTypeCodeByName(entityName) {

try {

var lookupService = new RemoteCommand(“LookupService”, “RetrieveTypeCode”);

lookupService.SetParameter(“entityName”, entityName);

var result = lookupService.Execute();

if (result.Success && typeof result.ReturnValue == “number”) {

return result.ReturnValue;

} else {

return null;

}

} catch (e) {

alert(“Error while getting ETC by Name – ” + e.description);

}

}

Hope it helps 🙂