cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Get the highest level manager for a user

Hello, 

 

I am trying to build a flow that returns the highest level manager, who is a level below the CEO in any given department. 

 

For example, person A reports to person B, who reports to person C who reports to person D, who reports to the CEO. I need the flow to return the name of person D. E.g. a marketing intern reporting to a marketing manager who reports to a senior manager who reports to the vp of marketing who reports to the chief marketing officer who reports to the CEO would return the chief marketing officer. 

 

How can I use the GetManager and Do Until features to achieve this? 

1 ACCEPTED SOLUTION

Accepted Solutions
MarvinBangert
Super User
Super User

Hi @Anonymous 

you can try the following:

Image 662.png

My trigger is a "manually trigger a flow" with an email as an input. Then I create two variables, "varMail" is the first value the Email input from my trigger and array is empty.

Image 663.png

On the do until I set the condition to my CEO (I hope that you only have one final email/CEO that you can also use as a filter, otherwise you would need to check for maybe Position or something, where you find the CEO value). In my test environment "Albert Einstein" is my CEO. The "Get Manager" UPN is my variable "varMail" which i reset on every run with a new mail from the manager I found. Using the function "iterationIndexes('Do_until')" I can get the index of the current run and save it in an compose (or you can also use a variable).

Last I add the mail to an array, which I will filter later.

Image 664.png

When your flow exits the do until, the current index is the index of your CEO, so you need to subtract the index of your CEO by 1 to get the level below. You use this function "add(outputs('Compose_2'),-1)" in your action "compose". The last action "compose 3" give you the value from the array using the index from your "Compose" action that we calculated: variables('varArray')?[outputs('Compose')].

That should be your mail address from the manager under CEO. 

 

Best regards
Marvin

If you like this post, give a Thumbs up. If it solved your request, Mark it as a Solution to enable other users to find it.

View solution in original post

2 REPLIES 2
MarvinBangert
Super User
Super User

Hi @Anonymous 

you can try the following:

Image 662.png

My trigger is a "manually trigger a flow" with an email as an input. Then I create two variables, "varMail" is the first value the Email input from my trigger and array is empty.

Image 663.png

On the do until I set the condition to my CEO (I hope that you only have one final email/CEO that you can also use as a filter, otherwise you would need to check for maybe Position or something, where you find the CEO value). In my test environment "Albert Einstein" is my CEO. The "Get Manager" UPN is my variable "varMail" which i reset on every run with a new mail from the manager I found. Using the function "iterationIndexes('Do_until')" I can get the index of the current run and save it in an compose (or you can also use a variable).

Last I add the mail to an array, which I will filter later.

Image 664.png

When your flow exits the do until, the current index is the index of your CEO, so you need to subtract the index of your CEO by 1 to get the level below. You use this function "add(outputs('Compose_2'),-1)" in your action "compose". The last action "compose 3" give you the value from the array using the index from your "Compose" action that we calculated: variables('varArray')?[outputs('Compose')].

That should be your mail address from the manager under CEO. 

 

Best regards
Marvin

If you like this post, give a Thumbs up. If it solved your request, Mark it as a Solution to enable other users to find it.

Anonymous
Not applicable

This worked great. Thank you for the solution.

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

MPA Licensing.jpg

Ask your licensing questions at the Power Automate AMA!

Join Priya Kodukula and the licensing team, super users and MVPs to find answers to your questions on Power Automate licensing.

Users online (2,078)