PowerApps navigate to previous screen functions makes it fairly easy to move from one screen to the next. Most apps will have more than a single screen. In an application with many screens it is worth thinking like the user of the app and anticipating where they may want to go next. It could be that your users will know what they want and will tell you which screen should show next.
There will be instances when you want them to return to the home or menu screen. It could be that they need to go to a screen which relates to the one they are currently on. So will PowerApps navigate to another screen functionality be beneficial for your app?
Most apps will benefit from having a main menu screen. This could consist of a series of buttons which take you to a screen for updating, adding or deleting information. It is a good idea to add a button to exit the app also.
I like to use an icon for a Home screen – when clicked the user would be taken to the start screen of the application – this could be the main menu. PowerApps navigate to previous screen functionality will be possible in this case.
PowerApps Navigate to Previous Screen in Two Ways
There are two ways of navigating between screens.
We can use: Navigate(ScreenName) or Back() These functions do not necessarily need to sit behind buttons. We can trigger them in other ways.
Can PowerApps Navigate to Previous Screen Seamlessly?
It certainly appears so and the way to do it is by using Navigate or Back.
PowerApps Navigation if Record is Saved or Not
Navigation can be used if a record is saved successfully. If the record is not saved and something has gone wrong then you may wish to display a message informing the user. Far better to tell the user what has happened than to leave them with a blank screen wondering what to do next. If your application is using forms, we can easily do this. Click on your form and look for the OnSuccess event. In here you can write code to move to the next screen. Navigate(ScreenName)
The PowerApps button onselect event is needed for when you want your button to do something. In the onselect event you will add your code to trigger an action. Without adding code in this event your button won’t be able to do anything.
Lets take a look at some of the possible actions we can put behind a button. One of the more popular ones is to move the focus to another screen. This is possible by using the ‘Navigate’ command. In the OnSelect event of the button we can write
We can also change the text of a label from the OnSelect event. In PowerApps set field value with button can be done by using a context variable.
For example, I add the following line to the OnSelect event.
This creates a screen variable called ‘Name’ and assigns the value ‘John’ to it.
Add a label to the screen and in the text property add the name of the variable you declared.
Another thing we can do is a PowerApps change label text on button click. In this case we would use a variable value to control colours.
Behind the OnSelect event of the button I use the following code to create a variable.
This creates a context variable called ‘togglevalue’. Then we use the exclamation mark to denote the command NOT. It turns the variable value to be the opposite of its current value. If it is true then the exclamation mark makes it become NOT true, in other words it becomes false.
Add a label and move it to the top of the screen. Expand it so that it fills the width of the screen.
Go to the properties and in the ‘Fill’ property add the following line:
Now run the application and click the button. You will see the label background colour change each time you click the button. The colour will change from red to blue and vice versa.
Change the visibility of a control
We can use the same variable to control whether a control is visible or invisible.
Add a gallery to the screen.
In the ‘visible’ property add the following line of code:
Run the application and click the button. The gallery will become visible and then invisible each time you click the button. Again, the variable in the OnSelect event is controlling all this – it is either True or NOT True when the button is clicked.
It is not just buttons that have an OnSelect event. You will also find this event on labels, text boxes, combo boxes, a gallery etc. Generally though, a button is the natural control for using the OnSelect event on.
The PowerApps button onselect event can especially be found on menu buttons, where navigation is needed to move to other screens. The onselect event is saying, when the button is selected ‘clicked’ then go and do something. That something will be determined by the code you write that sits in that event.
PowerApps button onselect change screen can be done by using the Navigate command. By selecting the onselect event you can add the Navigate command and enter the screen you wish to move to. The PowerApps onselect navigate ability makes switching between screens a breeze.