cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
BrianHFASPS
Responsive Resident
Responsive Resident

Unreliable User() check?

I have a checkbox that I want to activate and hide based upon who is using the app. It works in testing but doesn't seem to be reliable in production. Here is the code I have:

Default - If(User().Email = "User@fasps.org",true,false)
Visible - If(User().Email = "User@fasps.org",false,true)

The Visible piece seems to always work but the Default sometimes seems to be correct initially and then switches. I see the app react to it being one way and then flip. I can't reliably reproduce. So I am wondering if there is something I am missing or to check on why this isn't reliable.

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User III
Super User III

@BrianHFASPS 

The User() function does sometimes have a lag to it.

It is generally good practice to put any functions like that on the OnStart of the App.  Since the information will not change in the App, there is no need to constantly call the function.

So, in your OnStart, set a variable with this formula:

   Set(glbUserInfo, User())

 

Then on your checkbox, use the formula as such:

   Visible :   !(glbUserInfo.Email = "User@fasps.org")

   Default:  !checkBox.Visible

 

A couple of little things here - 1) the Visible property will be set to the NOT (!) of the true or false that is determined by the email check.  Although you can write out the formula with the If statement, you can shortcut it.

2) Rather than doing the check again in the default, here we just set the Default based on the formula results of the Visible property (and in this case, the Not(!) of that - according to your original formulas).

 

I hope this helps you some.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

2 REPLIES 2
RandyHayes
Super User III
Super User III

@BrianHFASPS 

The User() function does sometimes have a lag to it.

It is generally good practice to put any functions like that on the OnStart of the App.  Since the information will not change in the App, there is no need to constantly call the function.

So, in your OnStart, set a variable with this formula:

   Set(glbUserInfo, User())

 

Then on your checkbox, use the formula as such:

   Visible :   !(glbUserInfo.Email = "User@fasps.org")

   Default:  !checkBox.Visible

 

A couple of little things here - 1) the Visible property will be set to the NOT (!) of the true or false that is determined by the email check.  Although you can write out the formula with the If statement, you can shortcut it.

2) Rather than doing the check again in the default, here we just set the Default based on the formula results of the Visible property (and in this case, the Not(!) of that - according to your original formulas).

 

I hope this helps you some.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

Thanks for the options and ideas. The logic of only checking user on start makes perfect sense, it doesn't change in a session. I have updated my code and will test.

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

PowerPlatform 768x460.png

Microsoft Learn

Check out our new Discover Your Career Path blog post series and get all the details.

Users online (2,515)