cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
JimmyWork
Super User
Super User

On App Start check if user is in group, not always working

Hi

 

I have a powerapp where i check if the user is in a group, if the user is there i set a variable and if this variable is Yes i will then redirect the user to a new screen.

 

This works fine but sometimes it seems like the lookup does not happen and i wonder if i can force it to run or how to actually make sure this is started and checked on app start?

 

This is the code i use on the App Start, when it fails the user ends up with not getting redirected and the variable is not set.

The issue does not happen often but does happen.

Set(varUser, Lower(User().Email));
If(varUser in Concat(Microsoft365Groups.ListGroupMembers("GroupID-XXXXXXXXXXXXX").value,mail), Navigate(AgentScreen,ScreenTransition.None) && Set(varAgent, true) && Set(varMenu, "Unassigned"), Set(varMenu, "Open"));

 

1 ACCEPTED SOLUTION

Accepted Solutions
v-xiaochen-msft
Community Support
Community Support

Hi @JimmyWork ,

 

Could you tell me:

  1. How many records are in the group?
  2. At some point, which function does not work?( Does the If() function not work? )

 

At my knowledge, there are two possible reasons.

1.ListGroupMembers() function retrieves 100 members by default. There are more than 100 members in your group.

If the member is after the 100th member, the function will not retrieve him. The result will be wrong.

So, top field can modify its maximum search volume. The upper limit is 999.

 

2.Before the concat() function is completely executed, the If() function starts to execute.

I suggest you run the concat() function before the If() function and put it in a variable.

 

You could try the following code in onstatrt property :

Set(varUser, Lower(User().Email));

Set(varConcat,Concat(Microsoft365Groups.ListGroupMembers("GroupID-XXXXXXXXXXXXX", {'$top':999}).value,mail));

If(varUser in varConcat, Navigate(AgentScreen,ScreenTransition.None) ; Set(varAgent, true) ; Set(varMenu, "Unassigned"), Set(varMenu, "Open"));

 

Best Regards,

Wearsky

View solution in original post

8 REPLIES 8
JimmyWork
Super User
Super User

Bump

v-xiaochen-msft
Community Support
Community Support

Hi @JimmyWork ,

 

Could you tell me:

  1. How many records are in the group?
  2. At some point, which function does not work?( Does the If() function not work? )

 

At my knowledge, there are two possible reasons.

1.ListGroupMembers() function retrieves 100 members by default. There are more than 100 members in your group.

If the member is after the 100th member, the function will not retrieve him. The result will be wrong.

So, top field can modify its maximum search volume. The upper limit is 999.

 

2.Before the concat() function is completely executed, the If() function starts to execute.

I suggest you run the concat() function before the If() function and put it in a variable.

 

You could try the following code in onstatrt property :

Set(varUser, Lower(User().Email));

Set(varConcat,Concat(Microsoft365Groups.ListGroupMembers("GroupID-XXXXXXXXXXXXX", {'$top':999}).value,mail));

If(varUser in varConcat, Navigate(AgentScreen,ScreenTransition.None) ; Set(varAgent, true) ; Set(varMenu, "Unassigned"), Set(varMenu, "Open"));

 

Best Regards,

Wearsky

@v-xiaochen-msft Thank you i will try this, it will take some time to report back as the issue only happens sometimes. There is only 8 people in the group.

 

Is there anyway for me to force the app to need to wait until commands are finished before it starts and run?

For example i was thinking at the end set a new variable like.
varHasRun, then on the next screen i check if varHasRun is true, if it's false i run the commands again?

@v-xiaochen-msft I tested the code provided but with that code it will never switch screens, it will set the variable but the screen will stay on the same even if the variable is set. I will look more into it later i also added the && and tested same results.

v-xiaochen-msft
Community Support
Community Support

Hi @JimmyWork ,

 

Please try the code below:                        // Remove the lower() function

Set(varUser, User().Email);

Set(varConcat,Concat(Microsoft365Groups.ListGroupMembers("GroupID-XXXXXXXXXXXXX").value,mail));

If(varUser in varConcat, Navigate(AgentScreen,ScreenTransition.None) ; Set(varAgent, true) ; Set(varMenu, "Unassigned"), Set(varMenu, "Open"));

 

Best Regards,

Wearsky

@v-xiaochen-msft If i dont use the lower function certain lookups in the app wont work.
I will do some testing and report back, thank you for taking your time and answering me

@v-xiaochen-msft 

The below seems to work now, i will have to update app and see if i get any report on the screen not forwarding again. May i ask you why you removed the && and replaced it with ; in your code?

Set(varUser, Lower(User().Email));
Set(varConcatAgents,Concat(Microsoft365Groups.ListGroupMembers("GroupID-XXXXX").value,mail));
If(varUser in varConcatAgents, Navigate(AgentScreen,ScreenTransition.None) && Set(varAgent, true) && Set(varMenu, "Unassigned"), Set(varMenu, "Open"));

 

v-xiaochen-msft
Community Support
Community Support

Hi @JimmyWork  ,

 

According to your description, let me answer your question.

 

Use ‘;’ to be more standard.

You could use && in your code and it also works. It's also great.

 

Best Regards,

Wearsky

Helpful resources

Announcements
Super User 2 - 2022 Congratulations 768x460.png

Welcome Super Users

The Super User program for 2022 - Season 2 has kicked off!

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

<
Users online (2,577)