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

Cool concept for reducing repetition

So, this is not a "problem" posting, this is just to share a concept that has saved me a ton of copy/paste and constant maintaining. 

 

The Scenario:

One of our apps has a variable set of activities.  Each activity has a specific screen for it. The list of activities is maintained in a SharePoint list and is adjustable there (thus not having to "re-code" the app all the time).  This is all fine. 

BUT - the problem was that we had several places in the App where the user could choose activities based on a menu (gallery) of items (filtered by conditions).

The goal was for them to click on the item and then go to that activity screen.  We had the Screen Name in the SharePoint list, and then had to use a nasty long Switch statement to match the SharePoint string name and then Navigate to the actual screen. (Because you can't Navigate to a screen by a string name - see my Idea posting here and vote if you would like that.)  Again, all fine - except - this had to be maintained in several places in the App...got to be a pain.

 

So, here was the solution:

On the OnSelect of all the Galleries that need to go to an action, instead of the Switch statement, we set a global variable - Set(JumpToAction, nameOfScreenFromList)

In the app somewhere (and in our case we have a screen for "app stuff" only - not user exposed), we put a good ol' Toggle Control on it.

In the OnCheck of the Toggle we put the nasty switch statement. 

   Navigate(
      Switch(JumpToAction, 

          "scrnActionA", scrnActionA,

          "scrnActionB", scrnActionB,

          scrnNotSupported),
      Cover)

 

So, because the Toggle will respond globally, we set the Default property of the Toggle to !IsBlank(JumpToAction)

This way, any time the JumpToAction variable has a value, the toggle will "Check" and the statement will execute.

 

The only thing we had to do in the process was set a temp variable so that we could clear the JumpToAction variable to make the Toggle "re-arm".

 

SO...here is the result:

All Galleries that need to navigate based on the variable screen name in the OnSelect action:

    Set(JumpToAction, ThisItem.ScreenName)

 

In the Toggle:

   Default - !IsBlank(JumpToAction)

   OnCheck:

       UpdateContext({tempJumpTo:JumpToAction});
       Set(JumpToAction,"");

       Navigate(
           Switch(tempJumpTo,
              "scrnActionA", scrnActionA,

              "scrnActionB", scrnActionB,

              ... and so on ...

              scrnNotSupported),
         Cover)

 

That was it!  We now had a global routine for Navigating to screens that only had one place where we needed to maintain the "code".  

We do this also for global resets of Collections.  This way your Collect statement is in one place and when you need to reset it, you can just flip a switch with a variable.

 

I hope this is helpful to others.

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: Cool concept for reducing repetition

@MickywBack will return to the screen that was last "on the stack".  With this method, the toggle fires and the Navigate gets executed, but the screen with the toggle and formulas is never navigated to, so, therefore, it is not "on the stack".

In other words - wherever you Set the trigger for the toggle (Set(JumpToAction,...)) is the one that the Back function will go to.  The end user NEVER sees or gets stuck on the trigger page because it is never navigated to.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.

View solution in original post

5 REPLIES 5
KickingApps
Level 8

Re: Cool concept for reducing repetition

Excellent solution; thanks for sharing this.  I am going to give it a go in one of my apps.

Super User
Super User

Re: Cool concept for reducing repetition

Thanks for sharing this @RandyHayes. That's a really useful technique, to be able to trigger common code from a toggle. Well done!

Mickyw
Level 8

Re: Cool concept for reducing repetition

Thanks for sharing. I'm curious: how Back() function behaves in this case? Does it route to last user screen or to staff screen?

 

Mick

Super User
Super User

Re: Cool concept for reducing repetition

@MickywBack will return to the screen that was last "on the stack".  With this method, the toggle fires and the Navigate gets executed, but the screen with the toggle and formulas is never navigated to, so, therefore, it is not "on the stack".

In other words - wherever you Set the trigger for the toggle (Set(JumpToAction,...)) is the one that the Back function will go to.  The end user NEVER sees or gets stuck on the trigger page because it is never navigated to.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.

View solution in original post

BrownMango69
Level: Powered On

Re: Cool concept for reducing repetition

Wickedly clever - thanks for sharing this.

Helpful resources

Announcements
firstImage

Microsoft Business Applications Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

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

Top Kudoed Authors
Users Online
Currently online: 73 members 3,447 guests
Please welcome our newest community members: