Search code examples
dynamics-crm-2011fetchxml

FetchXML to Get 2nd Relation Entity


Is it possible to display fields from nested link-entities in a view?

I have 3 entities: statistics, account, and address. Statistics has a lookup to Account and account has a lookup to Address. I want fields from all these entities in the Statistics view.

I have tried this and get an error: To use this saved view, you must remove criteria and columns that refer to deleted or no-searchable items.

    <savedquery>
        <IsCustomizable>1</IsCustomizable>
        <CanBeDeleted>1</CanBeDeleted>
        <isquickfindquery>0</isquickfindquery>
        <isprivate>0</isprivate>
        <isdefault>0</isdefault>
        <returnedtypecode>10008</returnedtypecode>
        <savedqueryid>{df101ac4-2e4d-e311-9377-005056bd0001}</savedqueryid>
        <layoutxml>
          <grid name="resultset" object="10008" jump="sl_name" select="1" preview="1" icon="1">
            <row name="result" id="sl_statisticsid">
              <cell name="sl_amount" width="100" />
              <cell name="sl_date" width="100" />
              <cell name="sl_debtor" width="100" />
              <cell name="sl_divisioncode" width="100" />
              <cell name="sl_source" width="100" />
              <cell name="sl_statstype" width="100" />
              <cell name="relatedAccount.wl_towncity" width="100"/>
              <cell name="relatedAccount.relatedAddress.wl_city" width="100" />
            </row>
          </grid>
        </layoutxml>
        <querytype>0</querytype>
        <fetchxml>
          <fetch version="1.0" output-format="xml-platform" mapping="logical">
            <entity name="sl_statistics">
              <order attribute="sl_amount" descending="false" />
              <attribute name="sl_statstype" />
              <attribute name="sl_source" />
              <attribute name="sl_divisioncode" />
              <attribute name="sl_debtor" />
              <attribute name="sl_date" />
              <attribute name="sl_amount" />
              <link-entity name="account" from="accountid" to="sl_debtor" alias="relatedAccount">
                <attribute name="wl_towncity" />
                <link-entity name="wl_postalcode" from="wl_postalcodeid" to="wl_postaltowncity" alias="relatedAddress">
                  <attribute name="wl_city" />
                </link-entity>
              </link-entity>
              <attribute name="sl_statisticsid" />
            </entity>
          </fetch>
        </fetchxml>
        <LocalizedNames>
          <LocalizedName description="Statistics and Address" languagecode="1033" />
        </LocalizedNames>
      </savedquery>

If this line is removed then the view works:

<cell name="relatedAddress.wi_city" width="100" disableSorting="0" />

Does anyone know how to reference an element from a nested link-entity in the GridXML?

I have also tried this for the offending line:

<cell name="relatedAccount.relatedAddress.wi_city" width="100" disableSorting="0" />

It is starting to look like it is not possible to have a view that displays fields from nested link-entities.


Solution

  • This is not possible, according to the best of my knowledge, but please someone prove me wrong.

    A limitation of GridXML appears to be that attributes can only be included that are from the first link-entity, not any nested link-entities.