Search code examples
dynamics-crmmicrosoft-dynamicsfetchxml

Fetch XML returns 0 records where there is no related field


I'm using FetchXML to retrieve some field values for a few given IDs. The problem is that if I request a related field, and that field does not have a value, no records are returned.

For example, in using the following FetchXML, the Accounts for the given IDs do exist but since they DO NOT have a ParentAccount no values are returned.

<fetch  mapping="logical">
  <entity name="account">
    <attribute name="name" />
    <attribute name="ownerid" />
    <link-entity name="account" to="parentaccountid" alias="parentaccountid">
      <attribute name="name" />
    </link-entity>
    <filter>
      <condition attribute="accountid" operator="in">
        <value>9c8539fd-f7b1-e811-a973-000d3af4a510</value>
        <value>be76ea1b-f8b1-e811-a973-000d3af4a510</value>
        <value>1e76ea1b-f8b1-e811-a973-000d3af4a510</value>
        <value>50843103-f8b1-e811-a973-000d3af4a510</value>
        <value>b983ea1b-f8b1-e811-a973-000d3af4a510</value>
      </condition>
    </filter>
  </entity>
</fetch>

Is there something I need to add to the link-entity to indicate that if it is null to still return the rest of the values?


Solution

  • You can mention join to be an outer if that field will be null for some records.

    <link-entity name="account" to="parentaccountid" alias="parentaccountid" link-type="outer">
    

    Read more