web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / List of all direct rep...
Power Automate
Answered

List of all direct reports and subordinates

(6) ShareShare
ReportReport
Posted on by 203

I'm trying to build a Power Automate flow that will output a list of all every user that reports (both directly and indirectly) to a manager user ID (input).  I have tried to use the "Office 365 Users.Get direct reports" action, save the output to an array variable, and then loop through that array with the same "Get direct reports" action to return the next layer of users.  When finished, I would append all these lists together for a single complete list of all direct and indirect reports.

 

My issue is there could be 5+ layers of management in the organization, so I would like the flow to keep digging into each user until the "Get direct reports" returns nothing.  There has to be a simpler method than essentially an infinite number of embedded loops!

Categories:
I have the same question (2)
  • ChristianAbata Profile Picture
    8,953 Most Valuable Professional on at

    Hi @JimSutt  you can use do ultil.

    In my example I look into json response many time unless the answer is empty

    doultil.PNG

  • v-bacao-msft Profile Picture
    Microsoft Employee on at

     

    Hi @JimSutt ,

     

    Maybe you could consider using Do until to meet your needs.

     

    Please consider sharing the current Flow configuration so that we can try to apply Do until to your Flow.

     

    Best Regards,

  • JimSutt Profile Picture
    203 on at

    Hi @ChristianAbata and @v-bacao-msft ,

    I used your feedback and reconsidered my approach.  Below is what my process looks like thus far. 

     

    My approach is as follows:

    1. Prompt for manager's email
    2. Get manager's profile (email, name, job title)
    3. Initialize an array and add the manager's profile to first line of array
    4. Loop through the array, appending the manager's direct reports to the array.  As the array grows, the intent is the loop will keep evaluating the direct reports of each user, and continue to append the full-time users to the end of the array. 

    Currently, the main loop does not continue to process newly added users to the array, only the original.  Is there a way to continue to loop through the array as it grows?

    Office365GroupMgmt2-1.png

     

    Office365GroupMgmt2-2.png

     

    Office365GroupMgmt2-3.png

     

    Office365GroupMgmt2-4.png

     

     

  • JimSutt Profile Picture
    203 on at

    Note that I did not use the "Do Until" loop as I don't want the loop to stop when it hit the first user with no direct reports.  I want to keep building the list of direct reports and checking each one for additional reports.  I hope that makes sense.  I wonder if I need to use a different style of loop in order to loop through an array that is expanding.

  • tootuff Profile Picture
    16 on at
    I am also trying to accomplish this. Is there any update from Microsoft on a possible solution?
  • JimSutt Profile Picture
    203 on at

    Successfully implemented the logic using the Do Until function (see screenshots) and a counter.  It appears the Apply To Each loop only processes the rows of the array present at the START of the loop and ignores rows appended to the array during the loop.  

    The Do Until loop does not use the array as an input, but rather compares a simple counter to the size of the array.  Since the array is initialized with 1 row and the counter is initialized at 0, the loop will continue to process the array until the counter catches up to the size of the array, which is re-evaluated each iteration of the loop.  

    *Note:  The Get Direct Reports function returns inactive users, so my next course of action (not shown here) will be to ignore those records.  

    Office365GroupMgmt3-1.pngOffice365GroupMgmt3-2.pngOffice365GroupMgmt3-3.pngOffice365GroupMgmt3-4.pngOffice365GroupMgmt3-5.png

  • mikeyroth Profile Picture
    13 on at

    I would really appreciate some help.  I cannot figure out the variables used in the JSON Parse Content field in your screen shots.    I know I want the data from the items we stored in the array, I am just not sure how to get them.   Any advice?

  • JimSutt Profile Picture
    203 on at

    Hello @mikeyroth, the following is the code in the "Content" field of the Parse JSON step:

     

    variables('FinalArray')[variables('ArrayCounter')]

     

    The output of this step will give us the components of the object array for the current row, which we can then reference the "mail" element to pass into "Get direct reports (V2)".  If you need it, the following is the Schema used in the Parse JSON step:

     

    {
     "type": "object",
     "properties": {
     "Mail": {
     "type": "string"
     },
     "DisplayName": {
     "type": "string"
     },
     "JobTitle": {
     "type": "string"
     },
     "AccountEnabled": {
     "type": "boolean"
     }
     }
    }

     

    Hopefully this addresses your question.  If you need more help, please let me know.

  • mikeyroth Profile Picture
    13 on at

    @JimSutt   Thanks  I got it to run!   I found I had to change the limit of the do until to get all of the reports, but it did work.  Did you ever get where you could filter those accounts that were not enabled?

  • JimSutt Profile Picture
    203 on at

    Hi @mikeyroth , I'm glad you were able to get the flow to run.  Good catch with the loop limiter.  In order to filter out the disabled accounts, you will need to include "accountEnabled" field from the "Get direct reports (V2)" step.  After the "Get direct reports (V2)" step, add the "Filter array" step to only keep the records where accountEnabled = true.  You can also update the Select statement within your Do Until loop to save the value of the accountEnabled field (useful for testing to ensure you're only returning the correct values!)  The following is my updated steps immediately after "Get direct reports (V2)": 

     

    Office365GroupMgmt0-Filter.png

     

    The "Filter array" in advanced mode will look like:

    @equals(item()?['accountEnabled'], true)

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Haque Profile Picture

Haque 605

#2
Valantis Profile Picture

Valantis 340

#3
11manish Profile Picture

11manish 284

Last 30 days Overall leaderboard