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 / Dynamic Hierarchy stru...
Power Automate
Unanswered

Dynamic Hierarchy structure to grant access to records present in SharePoint list

(0) ShareShare
ReportReport
Posted on by 986

Hi everyone,
I recently have designed a flow that grants 2-level access to sharepoint records. To give you context I will explain it with an example:

I have a list named UserManagement that has the following structure:

Sidhant_02_0-1716451577346.png

(It has columns like Name, Email, Experience, DHId (Delivery Head Id), ReportingManagerEmail) like:

Sidhant_02_1-1716451698893.png

[Most of the columns are of Single line text type].
So I had constructed a flow which looks like:

Sidhant_02_2-1716451832738.png

Basically the intention of creating the above flow was to grant user -> Manager (RM) -> Manager's RM access so that what you see at the data source level is what you get in the application (without requiring any additional expression to manage it at application level using Filter expression).

Working of the flow:
-> Using Get Items I am retrieving all the records from the UserManagement list.

-> Then a check is (Condition action) been done to see if the record (as it is in loop: so it will take access all records one-by-one) ReportingManagerEmail column is empty or not (that means a given user does he/she have a Reporting Manager or not)

a) If the given user (record) has Reporting Manager (i.e. ReportingManagerEmail field is not empty/null):
-> Here first I am cutting off all the access for all users except (the Owners group of Sharepoint: They will be having the full control; So they will be able to see all the records this custom permission flow won't have any impact on them)
-> Then using the Grant access action: the record is being granted access for the user (Email), ReportingManagerEmail

Sidhant_02_3-1716452595844.png


Now to grant 2nd level access i.e. Reporting Manager's manager
[Assume Rahul (employee) -> Rohan (Reporting manager of Rahul) -> Sam (RM of Rohan)
So now all the actions below this are to give Rohan's RM i.e. Sam the access if his record is there in list]

Sidhant_02_4-1716452956498.png

In the Get Items 2 action I am retreiving RM's manager manager (in my example Rohan's RM is Sam) details and then granting the access (before that performing a check whether RM's manager manager is not empty: If it's not empty then proceed to grant access else do nothing.

b) If User has no reporting manager: (Condition 1: Returns null)
-> Then in this case I am just granting access only to the user. {This can be the case for Freshers}

 

As of now I have provided 2 level of access, but this won't be the case for all records like some might 2 levels, 3 levels, 4 levels.
For example:
Assume Shubham is a manager under him there are  3 individuals : Sushant, Radha, John. Out of these 3 users John has 2 reportee's (that report to him). So now Shubham should have access to 3 individuals that directly report to him (that is in ReportingManagerEmail column shubham's email will be present) and also he should be able to access John's team data as well.
And Shubham's manager is Samuel, so he should be able to access Shubham's record as well as the team that works under him and their team data as well.

So we cannot be sure how many levels we would have so I wanted to know how to achieve this dynamic behavior (currently I have designed my flow for 2/3 levels) even if I keep adding more apply to each as I am not sure how many levels, it would be difficult to track (current flow design is from bottom to up).

So I had a rough idea:
Suppose we get Samuels record we first check if he is RM for any of the user in our list or not: 
If he is then we initialize a list: Add all the members in it (his members in the list)
[Lets say 2 users report to Samuel: Jim, Ryan]
Then check if the members if they are Reporting manager for any of the other user if there is anyone who is RM, then for that individual create a list and all the members that report to him/her [Jim is RM: Sam]. Similarly check for the rest of them (i.e. Ryan)
And now Samuel add the sub-reportee's info (email) into Samuel's list) and now Samuel will have access to Jim,Ryan and Sam.

This is just rough idea but I am not sure how to implement that, whether it will be feasible or not. In the above approach will the flow size increase i.e. number of actions (then present structure). So if you guys have any idea about on how to approach this problem please let me know it will be quite helpful.

Regards,
Sidhant.

Categories:
I have the same question (0)
  • Sidhant_02 Profile Picture
    986 on at

    And one more thing is that we cannot be sure how many levels a user might have (in hierarchy) currently I considered 2 levels (user -> his/her manager -> manager's RM) but some users might have 4 levels, some 3 levels, some 2 levels. So accordingly the access needs to be provided instead of unnecessarily going to loops when its not required 
    Like: Jim's  Team-> Rock (Rock has no reportees)
    So Jim only has access to his record and his team records i.e. Rock.

  • Sidhant_02 Profile Picture
    986 on at

    So I created a flow wherein I had defined access level up till 4 levels (but still it is manual) it looks like:

    Sidhant_02_0-1716971665916.png

     

    Sidhant_02_1-1716971735249.png

    In the above Get items I am retrieving the user's immediate manager (RM) details. In Compose Super users I have defined 2 users (in an array: key-value pair like name and email)
    Then in the Apply to each 3 action (using the O/P of the Compose action) then extracting the email from Super users and in Compose L1 manager email (getting current users managers manager details) and in the condition doing a check to see if users manager's RM are they one of the super user:
    If Yes : then just grant the user and his RM the access (as in this RM = super user)
    Example:
    samuel - super user
    jim - super user
    John - User his RM : samuel
    (here samuel = super user; so only need to give john and samuel the access and end it)
    So currently there are 2 super users so once a match is found the necessary access should be given and it should come out from that loop, (for that I did add a variable with initial value 'true' and once the access is granted I am setting it to false inside the Yes Block, but as there 2 super users it still checks for the next super user which will go in false block for the same user)

    Like: John's RM= Samuel (who is one of the super user: Samuel ; other Super user is Jim) so I want to come out of Apply to each 3 loop so that it checks for next item, currently it keeps checking for the same item (here John with respect to 2nd Super user: jim and its obvious it will go in No block)
    So this is one issue (how to come out of nested apply to each block)

    Then the next part is for the 4 levels the flow looks:

    Sidhant_02_2-1716972566740.pngSidhant_02_3-1716972597969.pngSidhant_02_4-1716972648598.png



    The current setup is not dynamic but if you guys have some suggestions that can make the existing flow less complex it will be helpful.

    Regards,
    Sidhant.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
11manish Profile Picture

11manish 227

#2
David_MA Profile Picture

David_MA 204 Super User 2026 Season 1

#3
Valantis Profile Picture

Valantis 177

Last 30 days Overall leaderboard