Like parameters, variables are very helpful, and can be used to increase user communication in your app. A variable in Microsoft PowerApps is used with the function UpdateContext. Below are a few ways you can start using variables immediately in your apps.
User Communication
In a scenario where you’re sending data back to a source and doing a Patch, at times the user can be confused about what’s happening (if anything is going on at all). You might not want to take a user back to another page until the Patch is complete. To more effectively communicate to the user what is happening, try the following:
- Create a new app.
- Add a data source.
- Add a button that will send a record back to a source.
- Add the following code before your patch runs: UpdateContext({MyVariable:”Sending Data”});
- Add the following code after your patch runs: UpdateContext({MyVariable:” “})
- Update the Button Text to: If(MyVariable = “Sending Data”,MyVariable,”Send”)
Now your user will see the button change text to let them know what is happening.
Sending Data from Page to Page
There may be times when you want the user to interact with data on Screen 1, then pass some information to Screen 2 based on an interaction on the first screen. This becomes useful when you have a list of items on the first screen, and you want to show details on the second screen. To try this out, use the following steps:
- Create a new app.
- Add two screens.
- On the first screen, add a drop down.
- The OnChange property needs this: Navigate(Screen2,Fade,{MyVariable:Dropdown1.Selected.Value})
- On the second screen, add a text box.
- Set the text property to: MyVariable
Now you can pass variables from page to page. Variables will only live on that page that you are on. If you need global variables, then you can use a collection.
[divider line_type=”Small Line” custom_height=”20″]