Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 240
Bvrce Avatar asked Nov 14 '13 15:11

Bvrce


People also ask

How do I join data in fetchxml?

Inside FetchXML pt 2 – link-entity. To combine data from different records in your query you need to use the <link-entity> element. This is equivalent to a join in SQL. Each <link-entity> needs 3 key pieces of information: The entity type to link to. The attribute in the main entity to join from.

What is the difference between inner and outer join in fetchxml?

For example, the contact to marketing list relationship includes the listmember entity: FetchXML supports two link types – inner and outer. An inner join will include only records where there is a match across both entities. By comparison, outer join will include all the records from the first entity even if there is no match in the second entity.

How do I join two entities in a many-to-many relationship?

If you have a many-to-many (N:N) relationship you can’t join the entities directly, you have to join via the intermediate “intersect” entity.

What is the difference between fetchxml and SQL?

However, the FetchXML syntax is more restrictive than SQL as you can only use a single exact field match for the join criteria, rather than the complex criteria that you can use in a SQL ON clause (although it is possible to extend this a little further using a <filter> element which I’ll look at next time).


2 Answers

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.

like image 190
Bvrce Avatar answered Sep 29 '22 19:09

Bvrce


You can access data from related entities by nesting

<link-entity>

tags which is what you are doing in the code that you posted. What issues are you seeing with the fetchxml you have posted? Are you receiving an error or are you not getting correct results.

like image 30
Sunil Avatar answered Sep 29 '22 20:09

Sunil