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

IF and ELSE Function to rotate true and false

Hi,

 

Lets say i have got a button that every time it does thefollowing:

If A is enabled, disbale A and Enable B and If B is enabled, disbale B and Enable A

 

This is what i have in Button Action:

If(EnabledA;true) - UpdateContext({EnabledA: false}) & UpdateContext({EnabledB: true}) - (false) - UpdateContext({EnabledA: true}) & UpdateContext({EnabledB: false})

 

It seems just to do the last part: A Ends up enabled

If i remove the part in front of "-"  B stays enabled

 

I'm doing somethng wroug but i cant find the way to aply else or else if... something ike that...

 

Thank you in advance

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
PowerApps Staff CarlosFigueira
PowerApps Staff

Re: IF and ELSE Function to rotate true and false

I think I understand Smiley Happy. You can update multiple variables in the same UpdateContext call, and if you use the If function, you can perform an action in the case of the condition being true and another one in the case the condition is false. I think this should do what you need:

If(
    EnabledA;
    UpdateContext({EnabledA: false; EnabledB: true};
    UpdateContext({EnabledA: true; EnabledB: false})
)
3 REPLIES 3
PowerApps Staff CarlosFigueira
PowerApps Staff

Re: IF and ELSE Function to rotate true and false

You can use a single variable, and use the Not function (or the ! operator), to have opposite values for it. Here is one way you can implement that:

ButtonA.Disabled: !EnabledA
ButtonA.OnSelect: UpdateContext({ EnabledA: !EnabledA })

ButtonB.Disabled: EnabledA
ButtonB.OnSelect: UpdateContext({ EnabledA: !EnabledA })

When any button is clicked, the value of the EnabledA variable is toggled between true and false.

 

Hope this helps!

pedromoreno
Level: Powered On

Re: IF and ELSE Function to rotate true and false

I only have one button, and i want that button to control the 2 variables becouse they are used for other stuff also.

What you have just showed me should work very fine for other stuff that i can make simple.. thank you Smiley Happy

 

But i need to control that one with the IF statment.. any ideas Smiley Happy

Highlighted
PowerApps Staff CarlosFigueira
PowerApps Staff

Re: IF and ELSE Function to rotate true and false

I think I understand Smiley Happy. You can update multiple variables in the same UpdateContext call, and if you use the If function, you can perform an action in the case of the condition being true and another one in the case the condition is false. I think this should do what you need:

If(
    EnabledA;
    UpdateContext({EnabledA: false; EnabledB: true};
    UpdateContext({EnabledA: true; EnabledB: false})
)

Helpful resources

Announcements
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

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

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

SecondImage

Power Platform Summit North America

Register by September 5 to save $200

Top Kudoed Authors
Users Online
Currently online: 46 members 4,613 guests
Please welcome our newest community members: