Get Manager Hierarchy recursively using Power Automate

Posted by

Retrieving the manager hierarchy recursively using Power Automate can be useful in various scenarios, particularly in organizations where understanding the reporting structure is essential for operational efficiency, decision-making, and compliance. Here are some reasons why you might need to implement this functionality.

Understanding the Need

Imagine you’re working on a project within your organization, and you need to escalate an issue to your manager’s manager. However, locating this information quickly and efficiently can be a daunting task, especially in large organizations with complex hierarchies. That’s where the Microsoft Graph API comes into play.

The Microsoft Graph API Advantage

The Microsoft Graph API provides a powerful mechanism to access organizational data, including user profiles, group memberships, and manager relationships.

https://graph.microsoft.com/v1.0/me?$expand=manager($levels=max;$select=id,displayName)&$select=id,displayName

However, leveraging this API requires premium connectors or complex configurations, limiting accessibility for many users.

Using standard actions

Step 1: Initiate the Flow

Use a trigger action, such as a manual trigger, to initiate the flow.

Step 2: Initialize an array variable

Initialize an array variable “ManagerArray” to store Manager Information

Step 3: Initialize a string variable to Manager Information

Initialize a string variable to store User’s email address. You could either hardcode it or grab it from Flow context.

Step 4: Start the loop

Add a Get Manager (V2) action to retrieve the manager information for a specific user. Utilize the ‘HTTP’ action to send a GET request to the API endpoint.

  • Set the UserEmail variable with the Manager’s Email from the step above
  • Add the UserEmail to the ManagerArray variable

Step 5: Stop the Loop

If the response does not include manager information (indicating that the user is at the top of the hierarchy), stop the ‘do while’ loop.

Step 6: Store or Display Manager Hierarchy

Finally, display the array in an compose action

Leave a Reply

Your email address will not be published. Required fields are marked *