Home > CRM 2011 > How to get Object Type Codes of Entities in CRM 2011

How to get Object Type Codes of Entities in CRM 2011

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 🙂

Advertisement
  1. joon
    January 17, 2012 at 7:11 PM

    what is the differnece between Entity table and EntityView view?? i see that EntityView is the “SELECT * FROM [Entity] WHERE OverwriteTime = 0 AND ComponentState = 0”.
    What does these two fields OverwriteTime and ComponentState mean?? As in the Entity table, i get two entries fro Account entity based on my solutions and in EntityView, there is only one row?

    regards
    joon

  2. May 30, 2012 at 2:27 AM

    I believe OverWriteTime and Component State are, in some combination, set to 1 when the entity has been changed but not published.

  3. October 23, 2012 at 10:42 AM

    You can also specify the entity name:

    SELECT *
    From EntityView
    where Name = ‘Account’ — Entity Name
    ORDER BY ObjectTypeCode

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: