Manager Approval Chain Lookup
Given an employee, walk the Office 365 Users manager chain up to the C-level and return the full approval hierarchy for use in other flows.
Provided as-is, without warranty of any kind. Review and test each pattern in a non-production environment before deploying it to live automations. See our Terms.
Overview
This flow accepts an employee's email address and walks up their Office 365 manager chain, returning the complete approval hierarchy as a structured JSON array. It uses the Office 365 Users connector's Manager_V2 operation in a Do Until loop, stopping when no manager is found or a configurable maximum depth is reached. The output includes each manager's display name, email, job title, department, and their level in the chain.
Use Case
Any downstream flow or app that needs to know "who are all the managers above this person?" — approval routing, escalation chains, org chart generation, or compliance reporting.
Flow Architecture
Manual trigger
Manually trigger a flow (Instant — Button)Accepts a UserEmail string input — the email address of the employee whose manager chain should be looked up.
Initialize ChainArray
Initialize variableCreates an empty array variable that will collect each manager record as the loop walks up the org chart.
Initialize CurrentUserEmail
Initialize variableString variable seeded with the trigger's UserEmail input; it is reassigned to each newly found manager so the next loop iteration looks up that manager's manager.
Initialize LoopCounter
Initialize variableInteger counter starting at 0, incremented every time a manager is appended. Compared against flowlibs_MaxChainDepth to guard against infinite loops.
Initialize HasManager
Initialize variableBoolean flag initialized to true; flipped to false when the top of the chain is reached so the Do Until exits cleanly.
Do Until manager chain exhausted
Do untilLoops until HasManager is false OR LoopCounter is greater than or equal to flowlibs_MaxChainDepth. Each iteration looks up the current user's manager and, on success, appends them to ChainArray, sets CurrentUserEmail to the manager's email, and increments LoopCounter; on a miss it flips HasManager to false.
Get Manager (O365 Users — Manager_V2)
Office 365 Users — Manager_V2Inside the loop: calls Manager_V2 against CurrentUserEmail to retrieve that user's direct manager. Configured to run after both Succeeded and Failed so the next Condition can branch on the result.
If Manager found
If conditionEnvironment Variables
| Schema name | Type | Default | Description |
|---|---|---|---|
| flowlibs_MaxChainDepth | String | 10 | Maximum number of levels to traverse up the manager chain. Prevents infinite loops from circular org charts. Lower values (3-5) are good for direct approval routing; higher values (10-15) for full org chart traversal. Stored as String per the FlowLibs standard and converted with int() in the loop expression. |
Connectors & Connections
| Connector | API name | Actions used |
|---|---|---|
| Office 365 Users | shared_office365users | Manager_V2 (Retrieves the direct manager of a user; called once per loop iteration to walk the chain.) |
Note — All connections are referenced as solution connection references; the flow is portable between environments as long as a connection is mapped at import time.
Customization Guide
Almost every realistic variant of this flow can be implemented by changing environment variable values. A few cases require small edits inside the flow definition — those are called out explicitly below.
- Adjust max depth
- Change the flowlibs_MaxChainDepth environment variable value. Lower values (3-5) are good for direct approval routing; higher values (10-15) for full org chart traversal.
- Add more manager fields
- In the Append Manager To Chain action, add additional fields from the Manager_V2 response (e.g., officeLocation, mobilePhone, city) to enrich the manager records returned in the chain.
- Filter by department
- Add a Condition inside the loop after Get Manager to skip managers from specific departments, or stop the chain early when a target department is reached.
- Use as a child flow
- This flow is designed to be called from other flows via Run a Child Flow. The calling flow passes the UserEmail and receives the full chain JSON. Use a Parse JSON action in the parent flow to work with the response.
- Add error handling
- The Get Manager action runs after both Succeeded and Failed, with the Condition checking for 404 status. For production use, consider adding a Scope around the loop body with a Configure Run After on Failed to send notifications if the O365 Users connector is unavailable.
Key Expressions
The flow is intentionally light on Power Fx / WDL gymnastics — the heaviest expressions are the branch-name concatenation and the approval outcome check. They are listed below in the order they appear in the flow.
EXPR.01Loop exit condition
Used in the Do Until loop's exit condition: stops when no manager was found OR the loop counter reached the configured max chain depth. Note the int() wrap — the env var is stored as a String per the FlowLibs standard.
EXPR.02Manager email extraction
Pulls the mail field from the Manager_V2 response and assigns it to CurrentUserEmail so the next iteration looks up that manager's manager.
EXPR.03Chain depth count
Used in the Compose Result action to report how many managers were appended to the final ManagerChain output.
Comments
Sign in to join the conversation.
Sign inNo comments yet. Be the first to share your experience with this flow.