cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Yvonzim
Helper IV
Helper IV

Global variable not working

Hi, 

 

Hope i can explain my issue.

On Start i set a global variable based on an if statement (works)

When loading a screen i check that variable to disable or enable button display function

 

Variable is not empty but it is ignored:

it says UserCheckIn = false = false 

button.PNG

But when i check variable it is false (?) so UserCheckIn = false = true!

button 2.PNG

 

When i press the button, it wil set a new variable value, 

Set(UserCheckIn,false), from now on it does work.

 

My question is why does powerapps ignore the global value set in On Start?

 

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@Yvonzim 

Then you can also try to coalesce the value if it is not initialized properly.  Use this formula instead of your original:

    If(!(Coalesce(UserCheckIn, false)), Edit, Disabled)

 

_____________________________________________________________________________________
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

10 REPLIES 10
RandyHayes
Super User
Super User

@Yvonzim 

Please consider turning off the Use non-blocking OnStart rule in your advanced settings for the app.

 

I hope this is helpful for you.

_____________________________________________________________________________________
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!

I just checked and is turned off now, without succes.

but Variable is not empty when entering the screen where i use it.

 

Yvonzim_0-1607010384874.png

When false, " check uit"  button displaymode should be disabled.

 

 

 

RandyHayes
Super User
Super User

@Yvonzim 

Then you can also try to coalesce the value if it is not initialized properly.  Use this formula instead of your original:

    If(!(Coalesce(UserCheckIn, false)), Edit, Disabled)

 

_____________________________________________________________________________________
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

Yes! thank you so much, its working.

 

To Soon 😞

After i pressed the button and the variable had changed to true only the original string i used is working now

If(UserCheckIn=true, Disabled,Edit)

 

can i combine those 2? 

 

If(!(Coalesce(UserCheckIn, false)), Edit, Disabled) or If(UserCheckIn=true, Disabled,Edit)

 

RandyHayes
Super User
Super User

@Yvonzim 

Well, I'm confused - you're logic is the complete reverse in those statements.

Let's take the Not and the Coalesce out of the statement for simplicity for the moment, and now your formulas read as follows:

If(UserCheckIn, Edit, Disabled)   

If(UserCheckIn, Disabled, Edit)

You can't do both...you are saying if usercheckin is true then set the mode to Edit in one and in the other you are saying set the mode to Disabled if it is true.

How do you envision that working in one formula?

_____________________________________________________________________________________
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!

Excuse, i do make it more complicated then needed. Copy paste error.

 

this one is now working on loading the page for the first time:

If(!(Coalesce(UserCheckIn, true)), Disabled,Edit)

 

this one is working when updating the global variable (on that same page)

If(UserCheckIn=true, Disabled,Edit)

RandyHayes
Super User
Super User

@Yvonzim 
So then you really needed the control to be Disabled if the UserCheckIn was true, not false as I originally inferred from your post.

 

So then all is working now? 

 

By the way, you can remove the =true from your formula.  It is redundant.  i.e  If(UserChecIn, Disabled, Edit) is the same.

_____________________________________________________________________________________
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!

I started all over again, it seems working now with your solution.

Thank you again and sorry for the confusing stuff i posted.

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (2,142)