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 :-
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 🙂
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
I believe OverWriteTime and Component State are, in some combination, set to 1 when the entity has been changed but not published.
You can also specify the entity name:
SELECT *
From EntityView
where Name = ‘Account’ — Entity Name
ORDER BY ObjectTypeCode