web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Pages / Web API | iterate thro...
Power Pages
Unanswered

Web API | iterate through the organisation structure of a contact

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi,

 

We have a requirement where the account lookup (on a form within a webpage) should be pre-filled with an account of the contact (or parentaccount) where a specific field (xxx_IsAgency) is set to YES. 

 

For this purpose, the organization tree must be iterated recursively from the contact upwards and a stop must be made at the point where "xxx_IsAgency" = Yes can be found. This organization must then be stored in the account lookup field.

 

Any suggestions (maybe an example) how to properly define the WEB API for this request?

 

Thank you very much!

Categories:
I have the same question (0)
  • oliver.rodrigues Profile Picture
    9,471 Most Valuable Professional on at

    Hi, I don't think you need to run iterate through all the account records.

    You need a read operation "accounts where primarycontact = user.id and xxx_isAgency = yes"

    this might bring multiple results, so you might need to define a sorting criteria, and simply pick the first 

  • Fubar Profile Picture
    8,487 Super User 2026 Season 1 on at

    If it is multi-level hieratical you may need to look at 'above' or 'under' type conditions - not sure how this will go with the Web Api  https://docs.microsoft.com/en-us/power-apps/developer/data-platform/query-hierarchical-data

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi @Fubar,

     

    yes it is most likely multi-level hieratical. Do you know how to properly write it if the query should give me the first hieratical organisation that has the field set to yes?

     

    webapi.safeAjax({
    type: "GET",
    url: "https://"+ window.location.hostname+ `/_api/accounts(${accountId})?$select=`,
    contentType: "application/json",
    success: function (res) {

    E.g.

     

    Contact => Org 1 (field = no) ==> Org 2 (field = no) ==> Org 3 (field = Yes)

     

    Thanks!

     

     

  • Fubar Profile Picture
    8,487 Super User 2026 Season 1 on at

    Not sure if it will work with the Portal Web API, nor exactly what your query needs to be but the general 'Above' would be something like

    accounts?$select=name,accountid&$filter=(Microsoft.Dynamics.CRM.Above(PropertyName='accountid',PropertyValue='4149d512-6827-4b5d-b546-40f1be7e031f'))

     

    (use XrmToolBox and the FetchXML builder, you can then see what the oData equivalent is of the FetchXML)

     

    If the Portal Web API does not support it you can always revert to the old way of setting up a portal page with a liquid template making a FetchXML query and then calling that page via Ajax.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Pages

#1
rezarizvii Profile Picture

rezarizvii 61

#2
11manish Profile Picture

11manish 40

#3
oliver.rodrigues Profile Picture

oliver.rodrigues 36 Most Valuable Professional

Last 30 days Overall leaderboard