Reply
Highlighted
Level: Powered On
Posts: 19
Registered: ‎12-06-2016

Dynamically set onselect function

Has anyone ever dynamically applied what will occur within an onselect based on what has been defined within a collection. For example, on the home screen menu of an app I have created, I am using a collection to define what what appears and what does not appear. This collection is also used on other screens for a drop-down navigation. This approach allows me to keep all of the menus updated in one place instead of having to go to every screen.

 

I am now running to the scenario where I want to have one screen to present different data by passing parameters from home screen or app menu.

 

Can you pass functions as variables like the following:

 

{menulabel: "PowerApps RSS", onselect:"Navigate(RSSreader,ScreenTransition.Cover,{feedname: 'PowerApps', feedurl: 'https://powerapps.microsoft.com/en-us/blog/feed/'})"}, {menulabel: "Flow RSS", onselect:"Navigate(RSSreader,ScreenTransition.Cover,{feedname: 'Flow', feedurl: 'https://us.flow.microsoft.com/en-us/blog/feed/'})"}

 

Any direction or help is appreciated.

PowerApps Staff
Posts: 602
Registered: ‎05-04-2016

Re: Dynamically set onselect function

Creating an expression from a string value is currently not supported - please create a new feature request in the PowerApps Ideas board if you believe it's a scenario we should support.

 

For your scenario, you can consider specifying the parameters in a generic collection that will be available to the screen where the menu navigates. For example, if you have this in the OnVisible property of your first (menu) screen:

ClearCollect(menuOptions,
    { menuLabel: "PowerApps RSS", screen: RSSReader, params:
Table({ name:"feedname",value:"PowerApps" }, {name:"feedurl",value:"https://powerapps.microsoft.com/blog/feed/" })}, { menuLabel: "Flow RSS", screen: RSSReader, params:
Table({ name:"feedname",value:"Flow" }, {name:"feedurl",value:"https://us.flow.microsoft.com/blog/feed/" })}, { menuLabel: "Other", screen: AnotherScreen, params:
Table({ name:"first",value:"First value" })})

Then you can on the OnSelect property of the menu that navigates to that screen store the screen parameters in a collection:

ClearCollect(screenParameters, ThisItem.params);
Navigate(ThisItem.screen, ScreenTransition.Cover)

Now in the screens you can use a LookUp to retrieve the value that was passed to it. For example, in the RSSreader screen, the following two expressions will give you the value of the feedname and feedurl parameters:

LookUp(screenParameters, name = "feedname", value)
LookUp(screenParameters, name = "feedurl", value)

This is a very generic option that can be used for many scenarios.

 

Another alternative, if the parameters that are passed to the screens are always the same (which is the case in your example below), then we can use the parameters directly:

MenuScreen.OnVisible: ClearCollect(menuOptions,
    { menuLabel: "PowerApps RSS", screen: RSSReader, feedname:"PowerApps",feedurl:"https://powerapps.microsoft.com/blog/feed/"},
    { menuLabel: "Flow RSS", screen: RSSReader, feedname:"Flow",feedurl:"https://us.flow.microsoft.com/blog/feed/"})

MenuArrow.OnSelect:
    Set(feedname, ThisItem.feedname);
    Set(feedurl, ThisItem.feedurl);
    Navigate(ThisItem.screen, ScreenTransition.Cover)

And on the screens you can access the variables 'feedname' and 'feedurl' directly.

Level: Powered On
Posts: 19
Registered: ‎12-06-2016

Re: Dynamically set onselect function

Carlos,

Thank you for providing the different options. I ended up going with a hybrid of the options you provided. Given the navigation can be a combination of RSS and other features/functions, I have created a node called variables and I set a global variable with those values. For example,

 

{menuLabel: "Microsoft Flow RSS", screen: "RSSReader", variables: {rssLabel: "Micorsoft Flow RSS Feed", rssURL:"https://us.flow.microsoft.com/blog/feed/"}

 

so the onselect function looks like the following:

Navigate(ThisItem.screen,ScreenTransition.Cover);Set(menuVar,ThisItem.variables)

 

On the destination screen, I reference the values as such:

menuVar.rssLabel