cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Super User
Super User

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

Re: Trouble with Logic

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

Community Support
Community Support

Re: Trouble with Logic

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

Re: Trouble with Logic

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

Microsoft
Microsoft

Re: Trouble with Logic

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

Re: Trouble with Logic

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.

Super User
Super User

Re: Trouble with Logic

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}) )
Community Support
Community Support

Re: Trouble with Logic

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

Super User
Super User

Re: Trouble with Logic

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
MBAS Gallery 2020

MBAS Gallery 2020

Watch Microsoft Business Applications Summit sessions on-demand.

firstImage

New Ranks and Rank Icons released on April 21!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power Apps Community!

Top Solution Authors
Top Kudoed Authors
Users online (7,649)