cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Resolver I
Resolver I

Getting 5 levels line manager in a loop

Hi All,

I am trying to get the line manager of the current user and so on till the 5th level this can be done with:

Set(_glbUserLineManager1, Office365Users.ManagerV2(User().Email));
Set(_glbUserLineManager2, Office365Users.ManagerV2(_glbUserLineManager1.mail));
Set(_glbUserLineManager3, Office365Users.ManagerV2(_glbUserLineManager2.mail));
Set(_glbUserLineManager4, Office365Users.ManagerV2(_glbUserLineManager3.mail));
Set(_glbUserLineManager5, Office365Users.ManagerV2(_glbUserLineManager4.mail));

 

I am wondering if there is a better way to do this? Maybe with a collection or with a forall + with functions? anyone have any ideas?

Thanks.

2 ACCEPTED SOLUTIONS

Accepted Solutions
Microsoft
Microsoft

Hi @rssilvaba ,

 

Unfortunately, forall() function does not support this type of loop.

You cannot use variables in the forall() function.

Please refer to the following documents:

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-forall

 

However, you can use another method.

I create a collection and use the forall() function to loop 5 times, each time it returns a record. The value of the record is the mailbox.

 

You can try the following code:

1\ Add a button and set its onselect property to:

ClearCollect(AAA,{Test1: User().Email})

 

2\ Add a button and set its onselect property to:

ForAll(Sequence(5), Patch(AAA,Defaults(AAA),{Test1:Office365Users.ManagerV2(Last(AAA).Test1 ).mail}))

 

If you still have any question, please don't hesitate to let me know.

 

Best Regards,

Wearsky

View solution in original post

Hi @v-xiaochen-msft ,


Thanks for the tip. Your solution would work but I ended up going with:

 

ClearCollect(_glb_colLineManagers, Office365Users.ManagerV2(User().Email));
ForAll(Sequence(5), IfError(Collect(_glb_colLineManagers, Office365Users.ManagerV2(Last(_glb_colLineManagers).mail)),Blank()));

 

View solution in original post

2 REPLIES 2
Microsoft
Microsoft

Hi @rssilvaba ,

 

Unfortunately, forall() function does not support this type of loop.

You cannot use variables in the forall() function.

Please refer to the following documents:

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-forall

 

However, you can use another method.

I create a collection and use the forall() function to loop 5 times, each time it returns a record. The value of the record is the mailbox.

 

You can try the following code:

1\ Add a button and set its onselect property to:

ClearCollect(AAA,{Test1: User().Email})

 

2\ Add a button and set its onselect property to:

ForAll(Sequence(5), Patch(AAA,Defaults(AAA),{Test1:Office365Users.ManagerV2(Last(AAA).Test1 ).mail}))

 

If you still have any question, please don't hesitate to let me know.

 

Best Regards,

Wearsky

View solution in original post

Hi @v-xiaochen-msft ,


Thanks for the tip. Your solution would work but I ended up going with:

 

ClearCollect(_glb_colLineManagers, Office365Users.ManagerV2(User().Email));
ForAll(Sequence(5), IfError(Collect(_glb_colLineManagers, Office365Users.ManagerV2(Last(_glb_colLineManagers).mail)),Blank()));

 

View solution in original post

Helpful resources

Announcements
New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

Power Apps Community Call

Power Apps Community Call: February

Did you miss the call? Check out the Power Apps Community Call here.

Top Solution Authors
Top Kudoed Authors
Users online (76,947)