cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Toasteroven
Advocate II
Advocate II

If statement with boolean as argument

Hi there.

 

In my code i have a few variables i set up like UpdateContext({errornew1:true})

 

I would like to pass one of these into the argument of an if statement but i cant find any examples of syntax on how to do it. Ive tried some stuff like:

 

if(errornew1 = true,...,....)

if([errornew1],true,....,...)

 

Can anyone help me out with the correct syntax?

 

Thanks in advance

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
CarlosFigueira
Power Apps
Power Apps

You can use either the variable by itself, or compare it with true. For example, if you have a couple of buttons, each one setting the errornew1 variable to a true or false:

Button1.OnSelect: UpdateContext({errornew1:true})
Button2.OnSelect: UpdateContext({errornew1:false})

Then you can have a label with its Color property set to this expression:

If(errornew1 = true, Color.Red, Color.Blue)

Or, since errornew1 is already a boolean value:

If(errornew1, Color.Red, Color.Blue)

Both alternatives should work. As the value of the errornew1 variable is changed (in this case, by clicking the two buttons), the color of the label is toggled between blue and red.

View solution in original post

4 REPLIES 4
CarlosFigueira
Power Apps
Power Apps

You can use either the variable by itself, or compare it with true. For example, if you have a couple of buttons, each one setting the errornew1 variable to a true or false:

Button1.OnSelect: UpdateContext({errornew1:true})
Button2.OnSelect: UpdateContext({errornew1:false})

Then you can have a label with its Color property set to this expression:

If(errornew1 = true, Color.Red, Color.Blue)

Or, since errornew1 is already a boolean value:

If(errornew1, Color.Red, Color.Blue)

Both alternatives should work. As the value of the errornew1 variable is changed (in this case, by clicking the two buttons), the color of the label is toggled between blue and red.

View solution in original post

Oh i just needed errornew1 by itself the whole time? Wow haha I cant believe I never though of that.

 

Its all working now thankyou very much 🙂

Unfortunately, using Booleans with conditional statements does not always work. If the boolean value is an attribute of a record object, it is evaluated but the evaluation is not surfaced to the screen object (e.g. Label). I've encountered issues with this all over my apps with the current version of PA.

 

See attachments.

@GringoInMiami @Did you ever figure this out? I’m having the same issue.

 

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 (1,624)