cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Regular Visitor

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

Re: IF and ELSE Function to rotate true and false

I think I understand :). 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})
)

View solution in original post

3 REPLIES 3
Highlighted
Power Apps
Power Apps

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!

Highlighted
Regular Visitor

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 🙂

 

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

Highlighted
Power Apps
Power Apps

Re: IF and ELSE Function to rotate true and false

I think I understand :). 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})
)

View solution in original post

Helpful resources

Announcements
Check this Out

Announcing

Class of 2020- Season 2

Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

secondImage

Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (9,791)