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.
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.
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.
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.
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).
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With