Search code examples
dynamics-crmmicrosoft-dynamicsfetchxml

Microsoft Dynamics 365 can I use FetchXML to retrieve an entity by guid?


Given that I have a GUID and an Entity type, can I lookup the Entity using FetchXML?

Why doesn't the following obvious seeming FetchXML work?

<fetch>
  <entity name="user_entity" >
    <filter>
      <condition attribute="id" operator="eq" value="cb92c01d-8676-4f41-a5cf-8967cc9de0d9" />
    </filter>
  </entity>
</fetch>

Solution

  • Make sure GUID is valid for that entity record. I just quickly tested it in Dev Account entity for result (without any problems) from FetchXML Builder in XrmToolBox.

    <fetch version="1.0" output-format="xml-platform" mapping="logical" >
      <entity name="account" >
        <filter type="and" >
          <condition attribute="accountid" operator="eq" value="882E3BF1-97F9-E911-A813-000D3A5A1A59" />
        </filter>
      </entity>
    </fetch>
    

    Also similar to your query:

    <fetch>
      <entity name="account" >
        <filter>
          <condition attribute="accountid" operator="eq" value="882E3BF1-97F9-E911-A813-000D3A5A1A59" />
        </filter>
      </entity>
    </fetch>
    

    GUID is not case-sensitive too.

    <fetch>
      <entity name="account" >
        <filter>
          <condition attribute="accountid" operator="eq" value="882e3bf1-97f9-e911-a813-000d3a5a1a59" />
        </filter>
      </entity>
    </fetch>