Recently, I 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.
EDIT: Jonas Rapp provides a feedback to get more efficient with his tool 😉
The TL;DR; Answer
Use “Alias” + FetchXML editing using XrmToolBox (
View Designer + FetchXML Builder – this is the one stop shop!).
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…
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:
And I’ve set 2 teams for the testing purpose:
Team A with myself and Test User 1 as the member.
And Team B with Test User 2 as the member.
Now I have some records for testing purpose:
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 start with, I’ll export the FetchXML out of my initial query, it will look like this:
Now the trick is to use the “alias” of the related team entity to form the FetchXML like this:
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 🙂
Now, I want to put the query to the view, how to do that?
I’ll use XrmToolBox’s Fetch XML Builder to modify the FetchXML of the view. In my case, I’ve setup a Test Query view. Click on Open View….
And then select the corresponding view:
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 “OK” button down there and then click on the “Save As” button up there and save it back to the view.
And here’s the result: