cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Toasteroven
Level: Powered On

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
Power Apps Staff CarlosFigueira
Power Apps Staff

Re: If statement with boolean as argument

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

2 REPLIES 2
Power Apps Staff CarlosFigueira
Power Apps Staff

Re: If statement with boolean as argument

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

Toasteroven
Level: Powered On

Re: If statement with boolean as argument

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 🙂

Helpful resources

Announcements
thirdimage

Power Apps Super User Class of 2020

Check it out!

thirdimage

New Badges

Check it out!

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors
Users online (4,825)