cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
PN4567890
Helper II
Helper II

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 @PN4567890 

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 @PN4567890 

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.

PN4567890
Helper II
Helper II

This worked great. Thank you for the solution.

Helpful resources

Announcements
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.

Power automate tips 768x460 v2.png

Restore a Deleted Flow

Did you know that you could restore a deleted flow? Check out this helpful article.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Users online (1,419)