Posted on 5/16/2018 2:22:00 AM by Levin, AricBusiness Solutions Development Dynamics 365 Portals
In a recent project, we had a requirement to display cases to the portal that are associated with either Contacts or Accounts. Our case entity had a related entity called Case Contacts, and our account entity had a related entity called Account Contacts. The account entity had a list of all the cases associated with the account.
The issue that we had was that we could retrieve each list of cases individually, but the result could be duplicate where a case could be associated with both a Case Contact and an Account Contact.
We were struggling on whether to retrieve the first fetch, and then the second fetch and check the values that were part of the second fetch didn’t appear in the list of first fetches, or the alternative was to have a single fetch Xml that contained both conditions with an Or Condition in-between. The issue here is that advanced find does not allow created an Or condition with related entities.
Thanks to a post by Alex Shlega, we were able to do this easily. This can be done using XRMToolbox Fetch Xml Builder or just writing the Fetch Directly in a Text editing tool. The end result that we had was the following:
By adding the entity names to the Or Filter, we are able to specify conditions for the linked entities, and by doing this filter multiple linked entities with an Or Condition.
This resolves the issue of having to deal with duplicates in the results or having multiple result sets from separate Xml statements.