Question

How to get a list of all managers for a users?

Example:

  • User A reports to user B
  • User B reports to user C
  • User C reports to user D (CEO) and top of the hierarchy.

  • By giving user A I should get: [B,C,D]
  • By giving user B I should get:[C,D]
  • By giving user D I should get: []

Any API's or existing connectors that I can use to achieve that?

The hierarchy is already in place in AD

Was it helpful?

Solution

There is not a single API call that will walk up the hierarchy for you. But both Power Automate and the Graph API can retrieve a given user's Manager. Screenshot of the Get Manager action in Power Automate under the O365 Users category below:

enter image description here

To walk up the hierarchy, start by Initialize a variable of type string named something like lookupManager and set its initial value to be the current/chosen/selected user. Then Initialize a variable of type Arrary named something like managerChain. Then create a Do until loop set to run until lookupManager is null. Inside that loop, execute the Get Manager with the lookupManager as the input. If that action returns Success, then set foundManager to the newly found manager and also append it to your managerChain. In a parallel branch if the Get Manager action failed, then set foundManager to null which will cause the loop to stop.

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top