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.
Solved! Go to Solution.
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()));
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()));
User | Count |
---|---|
197 | |
124 | |
86 | |
49 | |
42 |
User | Count |
---|---|
284 | |
160 | |
135 | |
73 | |
73 |