How to get the Object Type Code of Custom Entity using Dynamics CRM Online/C# RRS feed

  • Question

  • Hi,

    I am facing an issue to retrieve the object type code of custom entity.

    I don't want to hardcode the value of object type code in the code because the object type code of the same custom entity could be different on the dev environment and on the prod environment.

    So, can you please let me know how we can get the object type code of the custom entity dynamically using c#.


    Thanks and Regards

    Wednesday, June 26, 2013 6:10 AM


  • by using metadata you can get object type code.

    using Microsoft.Xrm.Sdk.Messages;
    using Microsoft.Xrm.Sdk.Metadata;

     public string reterieve(string entitylogicalname)
                Entity entity = new Entity(entitylogicalname);
                RetrieveEntityRequest EntityRequest = new RetrieveEntityRequest();
                EntityRequest.LogicalName = entity.LogicalName;
                EntityRequest.EntityFilters = EntityFilters.All;
                RetrieveEntityResponse responseent = (RetrieveEntityResponse)_serviceProxy.Execute(EntityRequest);
                EntityMetadata ent = (EntityMetadata)responseent.EntityMetadata;
                string ObjectTypeCode = ent.ObjectTypeCode.ToString();
                return ObjectTypeCode;


    Wednesday, June 26, 2013 6:33 AM