Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How can I get entity logicalName from objecttypecode?

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi, may I ask is there any ways that I can fetch entity logicalname by providing the objecttypecode?

Thanks

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How can I get entity logicalName from objecttypecode?

    If anyone wants to just pull it with SQL you can grab it from the EntityView view.

    SELECT OriginalLocalizedName, LogicalName, ObjectTypeCode
    
     FROM [CHANGEME-DB Name].[dbo].[EntityView]
    
    ORDER BY OriginalLocalizedName, LogicalName asc


  • Suggested answer
    Andreas Cieslik Profile Picture
    Andreas Cieslik 9,267 on at
    RE: How can I get entity logicalName from objecttypecode?

    Hi Vivek,

    I would recommend to use PowerShell to activate tracing on your server to check and find out what is going wrong.

    support.microsoft.com/.../how-to-enable-tracing-in-microsoft-dynamics-crm

    If you create a new vanilla organization and open this link, do you also get this error?

    Cheers,

    Andreas

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How can I get entity logicalName from objecttypecode?

    Hi Andreas,

    I am getting following error when I try to access using the https://url/api/data/v8.2/EntityDefinitions

    I have dynamic 365 on premises version

    {

     "error":{

       "code":"","message":"An unexpected error occurred.","innererror":{

         "message":"An unexpected error occurred.","type":"System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]","stacktrace":"   at Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.Execute(OrganizationRequest request, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType, Boolean checkAdminMode, ExecutionContext executionContext)\r\n   at Microsoft.Crm.Extensibility.OData.CrmODataMetadataServiceDataProvider.RetrieveMetadataForEntityType(CrmODataExecutionContext context, Type crmType, EntityQueryExpression entityQuery, String entityId, String crmPropertyName)\r\n   at Microsoft.Crm.Extensibility.OData.CrmODataMetadataServiceDataProvider.RetrieveEdmEntityCollection(CrmODataExecutionContext context, String entitySetName, String castEntityName, ODataQueryOptions queryOptions)\r\n   at Microsoft.Crm.Extensibility.OData.EntityController.GetEntitySetInternal(String entitySetName, String castEntityName, CrmODataExecutionContext context, CrmEdmEntityObjectCollection crmEdmEntityObjectCollection, ODataQueryOptions queryOptions)\r\n   at Microsoft.Crm.Extensibility.OData.EntityController.GetEntitySet(String entitySetName)\r\n   at lambda_method(Closure , Object , Object[] )\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n   at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n   at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"

       }

     }

    }

    please any help or suggest

  • Suggested answer
    Andreas Cieslik Profile Picture
    Andreas Cieslik 9,267 on at
    RE: How can I get entity logicalName from objecttypecode?

    Actually you need this:

    https://customer.crm.dynamics.com/api/data/v8.1/EntityDefinitions?$select=SchemaName,ObjectTypeCode&$filter=ObjectTypeCode eq 1

    results in:

    {

    "@odata.context":"https://customer.crm.dynamics.com/api/data/v8.1/$metadata#EntityDefinitions(SchemaName,ObjectTypeCode)","value":[

    {

    "SchemaName":"Account","ObjectTypeCode":1,"MetadataId":"70816501-edb9-4740-a16c-6a5efbc05d84"

    }

    ]

    }

  • Suggested answer
    Andreas Cieslik Profile Picture
    Andreas Cieslik 9,267 on at
    RE: How can I get entity logicalName from objecttypecode?

    https://customer.crm.dynamics.com/api/data/v8.1/EntityDefinitions?$select=ObjectTypeCode&$filter=SchemaName eq 'Account'

    will give back the following json result:

    {

     "@odata.context":"https://customer.crm.dynamics.com/api/data/v8.1/$metadata#EntityDefinitions(ObjectTypeCode)","value":[

       {

         "ObjectTypeCode":1,"MetadataId":"70816501-edb9-4740-a16c-6a5efbc05d84"

       }

     ]

    }

  • Suggested answer
    Nadeeja Bomiriya Profile Picture
    Nadeeja Bomiriya 6,804 on at
    RE: How can I get entity logicalName from objecttypecode?

    Hi cowboy@arlington,

    I found some code from MVP Scott Durow's "SharePoint Integration from CRM Online Workflow/Plugin" which includes methods to fetch entity logical name from ObjectTypeCode.

    Original site is here.  The purpose of the original code was to parse DynamicUrl to get the Entity Reference.

    The class DynamicUrlParser includes Property EntityTypeCode (aka ObjectTypeCode).

    public class DynamicUrlParser
    {
        public string Url { get; set; }
        public int? EntityTypeCode { get; set; }
        public Guid? Id { get; set; }
    
    ....
    
    }

    There's a method in the DynamicUrlParser called GetEntityLogicalName.  This method gets the EntityLogicalName from EntityTypeCode.

    /// <summary> 
    /// Find the Logical Name from the entity type code - this needs a reference to the Organization Service to look up metadata 
    /// </summary> 
    /// <param name="service"></param> 
    /// <returns></returns> 
    public string GetEntityLogicalName(IOrganizationService service)
    {
        var entityFilter = new MetadataFilterExpression(LogicalOperator.And);
        entityFilter.Conditions.Add(new MetadataConditionExpression("ObjectTypeCode ", MetadataConditionOperator.Equals, this.EntityTypeCode));
        var propertyExpression = new MetadataPropertiesExpression { AllProperties = false };
        propertyExpression.PropertyNames.Add("LogicalName");
        var entityQueryExpression = new EntityQueryExpression()
        {
            Criteria = entityFilter,
            Properties = propertyExpression
        };
    
        var retrieveMetadataChangesRequest = new RetrieveMetadataChangesRequest()
        {
            Query = entityQueryExpression
        };
    
        var response = (RetrieveMetadataChangesResponse)service.Execute(retrieveMetadataChangesRequest);
    
        if (response.EntityMetadata.Count == 1)
        {
            return response.EntityMetadata[0].LogicalName;
        }
        return null;
    }
    

    That should do the trick.  Hope this helps.

    Cheers,

    Nadeeja

  • Suggested answer
    BharatPremji Profile Picture
    BharatPremji 2,485 on at
    RE: How can I get entity logicalName from objecttypecode?

    Hi,

    You can use the Metadata Document Generator in XRMToolBox :

    http://www.xrmtoolbox.com/

    This can output the entities of your choice into an Excel document and give you the entity type code and other useful information

    Regards

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,489 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans