Thursday, 8 August 2013

Get Object type code for MSCRM entities

  •  Using SQL Query :-
Get Object Type codes by Sql Query
SELECT ObjectTypeCode,*
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);