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!
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
Power Apps Portals Super User
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
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?
E.g.
Contact => Org 1 (field = no) ==> Org 2 (field = no) ==> Org 3 (field = Yes)
Thanks!
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.