Search code examples
c#dynamics-crmmicrosoft-dynamicsdynamics-365

How to find an entity name of a guid in Microsoft Dynamics 365 with c#?


I have a guid and I don't know that's for which entity. How can I find owned entity name? for example, there is a guid code: 7487cd8b-a0a2-eb11-b81e-005056a460ec. but what's the entity name?


Solution

  • How did you come across this Guid?

    In Dynamics, you should never have a record Guid without its entity/logical name. They almost always come together - if you don't see it, it's probably not too far!

    • In C# Dynamics SDK, lookup fields should always be EntityReference objects.

    • (The trickiest) If you're using the Web API HTTP requests, make sure to include annotations in your request header:

    Accept: application/json  
    Content-Type: application/json; charset=utf-8  
    OData-MaxVersion: 4.0  
    OData-Version: 4.0  
    Prefer: odata.include-annotations="*"
    

    This will include additional fields:

    _regardingobjectid_value@Microsoft.Dynamics.CRM.lookuplogicalname:"new_myentity",
    _regardingobjectid_value:"ad2d51c9-1de2-449d-b80a-76232503aacf",
    
    • If using Xrm.WebAPI, the annotations should be included by default.

    • In model-driven form javascript, formContext.getAttribute("regardingobjectid").getValue() will give you an array of Xrm.LookupValue objects containing both.

    entityType: "new_myentity", id: "{C8FE3743-2730-4625-85D5-325837015D8B}", name: "Name"}
    

    In a related note, I think it's a good idea to never put guids in variables, parameters or otherwise -- they are rather meaningless on their own as you have found -- always carry around EntityReference / Xrm.LookupValue objects instead.