cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
pedromoreno
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

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

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!

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 🙂

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

secondImage

Demo Extravaganza Winner Announcement

Please join us on Wednesday, July 21st at 8a PDT. We will be announcing the Winners of the Demo Extravaganza!

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Top Kudoed Authors
Users online (2,227)