cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ericonline
Community Champion
Community Champion

Trouble with Logic

Hello, 

 

I'm getting deeper into creating single-screen apps. These apps are largely controlled by UpdateContext logic. I'm having trouble with this nested If( And( function.

 

I'm reusing a single button on the screen. The OnSelect function is as follows: 

 

If(
    And(
        varStart,
        !varStep1,
        !varStep2),
            UpdateContext({varStart: false});
            UpdateContext({varStep1: true});
            ResetForm(activity_form);

    And(
        !varStart,
        varStep1,
        !varStep2),
            UpdateContext({varStep2: true}),
And( <----Here is the problem step !varStart, varStep1, varStep2), UpdateContext({varStep3: true}) )

The button works fine until the area of the Function noted above. I cannot get varStep3 to go true.

 

I verified that: 

  • varStart = false
  • varStep1 = true
  • varStep2 = true

But an additional button click does NOT set varStep3 to true. 

 

Can anyone see what i'm missing? 


Thanks

2 ACCEPTED SOLUTIONS

Accepted Solutions
RusselThomas
Microsoft
Microsoft

Hi ericonline,

 

First, I haven't stepped through the logic yet, but something that pops out at me;

 

If(
    And(
        varStart,
        !varStep1,
        !varStep2),
            UpdateContext({varStart: false});
            UpdateContext({varStep1: true});
            ResetForm(activity_form); <------ is this supposed to be a ; or a , ?

    And(
        !varStart,
        varStep1,
        !varStep2),
            UpdateContext({varStep2: true}),

    And(                         <----Here is the problem step
        !varStart,
        varStep1,
        varStep2),
            UpdateContext({varStep3: true})
)

 

Just a comment on the side - I love building single-page apps with reusable popups.  Something I realised though is that there is often a trade-off on complexity and performance vs usability (not to mention troubleshooting :)). 

It's still very much my style to build 1 or 2 pagers, but I've had other authors comment that my apps are difficult to maintain and/or hand over because the logic is so convoluted.

 

As a result, I've started asking myself often, 'is this really adding to the user experience?' when I find my context logic becoming a bit top-heavy.  

 

I still use reusable elements and pop-ups in every single app, but I've generally found users aren't really fussed, or hardly notice screen changes, and unless they seriously bloat your app, neither does PowerApps.  Just my 10c 🙂

 

 

Kind regards,


RT

View solution in original post

v-xida-msft
Community Support
Community Support

Hi @ericonline,

 

Could you please share a bit more about the varStart, varStep1, varStep2 and varStep3 that you mentiond within your formula?

Further, could you please share more details about the initialize value of above variables that you mentioned?

 

I assume that the initialize value of these variables as below:

 

varStart->false

varStep1->true

varStep2->true

varStep3->true

 

 

I have made a test on my side, the If(And( function works well on my side. Please take a try with the following workaround:

 

Set the OnVisible property of the first screen to folloowing formula:

 

UpdateContext({varStart:true});
UpdateContext({varStep1:false});
UpdateContext({varStep2:false});
UpdateContext({varStep3:false})

Set the OnSelect property of the Button control to following formula:

If(
    And(
        varStart,
        !varStep1,
        !varStep2),
            UpdateContext({varStart: false});
            UpdateContext({varStep1: true});
            ResetForm(activity_form), /** replace ; with , **/
    And(
        !varStart,
        varStep1,
        !varStep2),
            UpdateContext({varStep2: true}),
    And(                        
        !varStart,
        varStep1,
        varStep2),
            UpdateContext({varStep3: true})
)

 

 

In addition, I have made a test on my side, if you use ; (semicolon) within the following formula, the varStep3 varriable would not be set to true. 

If(
    And(
        varStart,
        !varStep1,
        !varStep2),
            UpdateContext({varStart: false});
            UpdateContext({varStep1: true});
            ResetForm(activity_form); /* If you use ; (semicolon) rather than ,(comma) here, the varStep3 variable would not be set to true */

    And(
        !varStart,
        varStep1,
        !varStep2),
            UpdateContext({varStep2: true}),

    And(                         
        !varStart,
        varStep1,
        varStep2),
            UpdateContext({varStep3: true})
)

 

Best regards,

Kris

 

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
ericonline
Community Champion
Community Champion

@Anonymous, you helped me on this type of thing earlier this week. Can you spot the issue here? I appreciate your assistance!

RusselThomas
Microsoft
Microsoft

Hi ericonline,

 

First, I haven't stepped through the logic yet, but something that pops out at me;

 

If(
    And(
        varStart,
        !varStep1,
        !varStep2),
            UpdateContext({varStart: false});
            UpdateContext({varStep1: true});
            ResetForm(activity_form); <------ is this supposed to be a ; or a , ?

    And(
        !varStart,
        varStep1,
        !varStep2),
            UpdateContext({varStep2: true}),

    And(                         <----Here is the problem step
        !varStart,
        varStep1,
        varStep2),
            UpdateContext({varStep3: true})
)

 

Just a comment on the side - I love building single-page apps with reusable popups.  Something I realised though is that there is often a trade-off on complexity and performance vs usability (not to mention troubleshooting :)). 

It's still very much my style to build 1 or 2 pagers, but I've had other authors comment that my apps are difficult to maintain and/or hand over because the logic is so convoluted.

 

As a result, I've started asking myself often, 'is this really adding to the user experience?' when I find my context logic becoming a bit top-heavy.  

 

I still use reusable elements and pop-ups in every single app, but I've generally found users aren't really fussed, or hardly notice screen changes, and unless they seriously bloat your app, neither does PowerApps.  Just my 10c 🙂

 

 

Kind regards,


RT

View solution in original post

Anonymous
Not applicable

If(
    And(
varStart, !varStep1, !varStep2
), UpdateContext({varStart: false}); UpdateContext({varStep1: true}); ResetForm(activity_form), // this should be , not ; And( !varStart, varStep1, !varStep2
), UpdateContext({varStep2: true}), And( !varStart, varStep1, varStep2
), UpdateContext({varStep3: true}) )

 

@RusselThomas  is right it should be , instead of ;

 

I also suggest using multi screen apps as opposed to single screen apps to simplify readability of the code.

Hello @RusselThomas and @Anonymous. Thank you very much for your input re: simplicity and single-screen apps. I hear ya! This is my first attempt at single-screen. I actually like this method so far as this is a rather simple 4 step app. Defining var's for "steps" that would normally be screen transitions is cool. Allows me to add in progress bars, control popups, button text, visibility, etc. with one value instead of defining it separately. 

 

Anyway: 

 

I had cut out two lines of the posted code (to simplify) and forgot to kill that last ";". So the ";" isn't a factor here. Here's the actual code.  


Can you see where the actual error/issue is? 

 

If(
    And(
        varStart,
        !varStep1,
        !varStep2),
            UpdateContext({varStart: false});
            UpdateContext({varStep1: true});
            ResetForm(activity_form);
/* Cut out of original post, forgot to clip that last ";". Sorry for confusing things :) UpdateContext({sigBox1Reset: true}); UpdateContext({sigBox1Reset: false}); UpdateContext({sigBox2Reset: true}); UpdateContext({sigBox2Reset: false});
*/ And( !varStart, varStep1, !varStep2), UpdateContext({varStep2: true}), And( // I can get all the way here, but can't toggle varStep3 true// !varStart, varStep1, varStep2), UpdateContext({varStep3: true}) )
v-xida-msft
Community Support
Community Support

Hi @ericonline,

 

Could you please share a bit more about the varStart, varStep1, varStep2 and varStep3 that you mentiond within your formula?

Further, could you please share more details about the initialize value of above variables that you mentioned?

 

I assume that the initialize value of these variables as below:

 

varStart->false

varStep1->true

varStep2->true

varStep3->true

 

 

I have made a test on my side, the If(And( function works well on my side. Please take a try with the following workaround:

 

Set the OnVisible property of the first screen to folloowing formula:

 

UpdateContext({varStart:true});
UpdateContext({varStep1:false});
UpdateContext({varStep2:false});
UpdateContext({varStep3:false})

Set the OnSelect property of the Button control to following formula:

If(
    And(
        varStart,
        !varStep1,
        !varStep2),
            UpdateContext({varStart: false});
            UpdateContext({varStep1: true});
            ResetForm(activity_form), /** replace ; with , **/
    And(
        !varStart,
        varStep1,
        !varStep2),
            UpdateContext({varStep2: true}),
    And(                        
        !varStart,
        varStep1,
        varStep2),
            UpdateContext({varStep3: true})
)

 

 

In addition, I have made a test on my side, if you use ; (semicolon) within the following formula, the varStep3 varriable would not be set to true. 

If(
    And(
        varStart,
        !varStep1,
        !varStep2),
            UpdateContext({varStart: false});
            UpdateContext({varStep1: true});
            ResetForm(activity_form); /* If you use ; (semicolon) rather than ,(comma) here, the varStep3 variable would not be set to true */

    And(
        !varStart,
        varStep1,
        !varStep2),
            UpdateContext({varStep2: true}),

    And(                         
        !varStart,
        varStep1,
        varStep2),
            UpdateContext({varStep3: true})
)

 

Best regards,

Kris

 

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

All three of you were correct. Even though I cut out those two lines of code... they last line STILL had a semicolon. Wow. Really lends credence to your "simplicity" piece doesn't it! 

 

Take care and thank you for looking into this issue. 

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

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.

Users online (2,617)