If you are looking to get the Entity Type Code or ETC (as it is generally known as) dynamically for any entity name in your web resource in MS
CRM, you should use the MetaData service to do so. The MetaData service in MS
CRM 2011 will retrieve all the Meta information about an entity. This information includes the display name of the entity, the logical name of the entity and all other information about its relationship status etc. However the information that we are interested in here is the "ObjectTypeCode".
How to build your MetaData service? For building a MetaData service you can use sample code provided in the
CRM SDK itself. (samplecode\js\soapforjscript\soapforjscript\scripts). The name of the file is sdk.metadata.js.
This javascript file has a function by name RetrieveAllEntitiesAsync. This function fetches all the entities with with their MetaData information. On success this function returns you entityMetadataCollection. Now all you need to do is to loop over entities and get the Object Type Code. Please follow the code below to get the Object Type Code or ETC.
function
successRetrieveAllEntities(entityMetadataCollection) {
for
(
var
i = 0; i < entityMetadataCollection.length; i++) {
var
entity = entityMetadataCollection[i];
var
objTypeCode = entity.objectTypeCode;
}
}
This is a supported way of getting etc or ObjectTypeCode of an entity.
Hope this helps.