Skip to content

Just My Blog

Just great and interesting articles and more!

  • Home
  • Tips & Tricks
  • Toggle search form

Query hierarchical data using FetchXML

Posted on 5 Oct 202210 Mar 2024 By Mohamed Elgharably

Condition operators for hierarchical data are great for getting hierarchical data using FetchXML like (above, under, eq-or-under, etc.….), you can find the full list of the operator here:

https://docs.microsoft.com/en-us/powerapps/developer/data-platform/query-hierarchical-data#condition-operators-for-hierarchical-data

Example: These operators can be used to get all user’s managers to know the eligible user which has to approve a certain discount (Discount Authority Matrix).

FetchXML will be like this:

<fetch distinct="false" no-lock="false" mapping="logical" >
   <entity name="systemuser" >
       <attribute name="fullname" />
       <filter type="and" >
           <condition attribute="systemuserid" operator="above" value="{00000000-0000-0000-0000-000000000000}" />
       </filter>
   </entity>
</fetch>

The result will be:

<resultset morerecords="0">
  <result>
    <fullname>Sales Supervisor</fullname>
  </result>
  <result>
    <fullname>Sales Manager</fullname>
  </result>
</resultset>

For more examples kindly refer to this useful topic:
Get all Contacts of All Hierarchical Accounts Using FetchXML and Web API
https://www.nexsoftsys.com/articles/get-all-contacts-of-all-hierarchical-accounts-using-fetchxml-and-web-api.html

Note: You can use aggregate to get the count of child records below the referenced record in the hierarchy.

FetchXML:

<attribute name="systemuserid" rowaggregate="CountChildren" alias="UserChildren" />

Result:

<UserChildren formattedvalue="2">2</UserChildren>

Related articles

Hierarchical Data With SSRS Reports – Recursive FetchXML
https://community.dynamics.com/crm/b/magnetismsolutionscrmblog/posts/crm-2011-retrieve-hierarchical-records-recursive-fetchxml

Execute Multiple Retrieve

Using the ExecuteMultipleRequest Message to Perform Bulk Retrievals from Dynamics 365
https://www.linkedin.com/pulse/using-executemultiplerequest-message-perform-bulk-from-elsherbeny/?trackingId=kBEH9a4ESUmQjA1JHMTm6w%3D%3D

ExecuteMultipleRequest Class
https://docs.microsoft.com/en-us/dotnet/api/microsoft.xrm.sdk.messages.executemultiplerequest?view=dynamics-general-ce-9

Dynamics CRM Tags:FetchXML

Post navigation

Next Post: How to add a pre-filter to SSRS Report using FetchXML

Categories

  • Azure (2)
  • Azure DevOps (2)
  • Dynamics CRM (4)

Tag cloud

Application Insights (1) Cloud flows (2) DevOps (3) FetchXML (2) Monitoring (2) Reports (1) SSRS (1)

Dynamics CRM Newsfeed

  • Smarter callbacks with availability-aware scheduling CCaaS APIs
  • AI in sales: Applying historical lessons to modern challenges 
  • Get started with agents for finance: Learnings from 2025 Gartner® CFO & Finance Executive Conference
  • The power of proactive engagement in Dynamics 365 Contact Center
  • Seamless scheduling across time zones in Dynamics 365 Field Service

Copyright © 2024 Just My Blog -

Powered by PressBook WordPress theme