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
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

Power Apps Community Call

Monthly Power Apps Community Call

Did you miss the call?? Check out the Power Apps Community Call here!

secondImage

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV STudio

Power Platform ISV Studio

ISV Studio is the go-to Power Platform destination for ISV’s to monitor & manage applications post-AppSource publish.

Top Solution Authors
Top Kudoed Authors
Users online (70,812)