Lots of tables in Dynamics CRM use the ObjectTypeCode to identify the entity. Sure, we all remember that Account is ObjecTypeCode 1 and Contact is ObjectTypeCode 2… But what about your custom entities, which start at 10,000 and are not guaranteed to be the same in different organizations, even if you have the same solutions installed — how will we remember their ObjecTypeCode values?
You don’t remember them, you query them when they need you. It’s quick and easy if you are on premises and have access to the SQL database. (If you don’t, ask your DBA to create a view with this query and give you rights to it.)
select coalesce(OriginalLocalizedName,name) as DisplayName, Name as SchemaName, ObjectTypeCode
order by ObjectTypeCode
Much easier than memorizing, and avoids the problems of remembering the wrong number for the wrong organization or deployment. Oops!
0 thoughts on “Getting Dynamics CRM ObjectTypeCode values via SQL”
Very helpful. Thank you so much
Quick question though, the entity type code for certain custom entities in our Prod is different to that of the dev instance, although they are promoted from the Dev as managed solutions. Any ideas?
We are experiencing the same issue, any ideas?
Codes for custom entities will potentially be different in different environments. I agree, it is frustrating! You have to determine the code by name before using it directly.