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

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
v-xiaochen-msft
Community Support
Community Support

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
v-xiaochen-msft
Community Support
Community Support

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

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()));

 

Helpful resources

Announcements
October Events

Mark Your Calendars

So many events that are happening this month - don't miss out!

Ignite 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Top Solution Authors
Top Kudoed Authors
Users online (4,094)