By Alexandra Tucker
January 29th, 2018

Barhead’s Solution Architect Andre Margono blog.

FetchXML Trick – Cross Entity Criteria in a Group Filter

Recently, Andre had a tricky question: Can you create a view that is displaying records that are either owned by a team or the users that are a member of that particular team.

The TL;DR; Answer

Use “Alias” + FetchXML editing using XrmToolBox (View Designer + FetchXML Builder).

The Longer Answer

The typical answer to the above scenario would be querying the record with the criteria as “Owner ID = the team OR related Owner (user) is a team member of the team”. Using the Advanced Find query, typically this is the query…

Typical_Adv_Find_Query.png

However, it seems we can’t group the “main” criteria and the Linked-Entity criteria. Looks like we are stuck here… Worry not, there is a trick for that. So, before I go to the solution here are some setups to set the background.

I have 3 users in my instance:

UserList.png

And I’ve set 2 teams for the testing purpose:

Team A with myself and Test User 1 as the member.

Team_A.png

And Team B with Test User 2 as the member.

Team_B.png

Now I have some records for testing purpose:

Sample_Data.png

So, when based on the query to see the Team A records, I would expect to see 3 records there. Using the initial query (above) will return no result, as it is treated as ‘AND’ operation.

To get the FetchXML correctly, I need to edit the FetchXML, my go-to tools for this would be XrmToolBox‘s FetchXML Builder.

To start with, I’ll export the FetchXML out of my initial query, it will look like this:

Base_FetchXML.png

Now the trick is to use the “alias” of the related team entity to form the FetchXML like this:

ModifiedXml.png

As you can see above, we are able to set the condition in the “main” filter and set the operator to OR. Below is the result of the fetch… it works as expected 🙂

TestResult.png

Now, I want to put the query to the view, how to do that?

I’ll use XrmToolBox’s View Designer to modify the FetchXML of the view. In my case, I’ve setup a Test Query view. Click on the Edit Query, this will open up the FetchXML builder.

EditQuery.png

Copy & Paste the FetchXML that we had tested previously into the FetchXML window, if you wish, you could test execute the query. Then click on the “Return FetchXML” button up there to go back to the View Designer.

FetchXMLThenReturn.png

Then click on Save and then Publish..

SavePublish.png

And here’s the result:

FinalResult.png

Follow Andre on his blog for more tools and tricks or follow Barhead on Linked in / 1300 DYN 365 / info@barhead.com

 

By Alexandra Tucker
January 24th, 2018

Stay up to date on the latest tips and tricks and trends by following Barhead’s Functional Consultant Elaiza Benitez who is keeping our clients educated and informed across a range of topics and Dynamics features.

This week #benitezherevlog is showing how users can self register using an additional entity form action #zerocode #configurationonly #msdyn365