Using Timer to Control Auto Navigation between Screens in Power Apps

Introduction

Timer control in Power Apps offers some handy features which can be used in unison with various features to complete the business flow of the app. There can be situations where we need to change the property of control based on the time elapsed after a specific activity, use the count down of the timer to wait for and trigger an action or even implement some cool looking marquee animations or fly out menus

In this article, we will see how we can make use of a timer control to automatically navigate across screens.

Scenario

We have a requirement where we have a Home Screen that lists out a few basic controls that let us navigate to various screens.

Diagram

Description automatically generated

Clicking one of them will take us to the respective screens where we will perform some operations like adding a new record.

Graphical user interface

Description automatically generated

Clicking on Save Stock will show the success screen. Now once we are in the Success Screen, we have a requirement to automatically navigate back to the home screen after 5 seconds without any manual intervention of using a close button or pressing the back button.

Implementation

To achieve this, we have created a sample app with 3 screens.

  • Home Screen with the basic screen navigation controls
  • Incoming Stock Screen to update the stocks details and save it to SharePoint
  • Success Screen to show the success message to the users

We will start with making change to the screen where we add the stock input. In the On Select of the Save Stock button. We will add the below expressions:

Patch(‘Medical Inventory’,{Medicine:TextInput_Medicine.Text,Count:TextInput_Count.Text,Department:TextInput_Department.Text,’Stock Date’:TextInput_StockDate.Text});
Navigate(Screen_SuccessScreen);
Set(StartTimer,true);

Here we have a normal patch function to save the details to SharePoint List. Followed by that, we will navigate to the Success screen and at the same time, declare and set a Global Variable StartTimer to true. We will use this value to define the start state of the timer we are going to use in the implementation.

Graphical user interface

Description automatically generated

Now we will move on to the Success Screen where we will add a timer control and set its Duration to 5000 which indicates 5000 milliseconds or 5 seconds. Its visibility is turned off as we don’t have to display it to the end-user.

Graphical user interface, website

Description automatically generated

We will also set the Start property to the Boolean variable StartTimer which we had set in the previous screen. While navigating to this screen, we will set it to true from the previous screen, which will start the timer to run for the 5 Seconds duration which we have mentioned in the Timer property.

Graphical user interface, text

Description automatically generated

We will now define the redirection logic in the OnTimerEnd property of the timer by adding the Navigate function so that it navigates to the home screen. As we no longer need the timer running, we will set the Timer variable(StartTimer) to false

Graphical user interface

Description automatically generated

Test the Timer Control

Now let’s go ahead and test the Timer control in action. Clicking on the Save button in the input screen will navigate the app to the Success screen. The timer starts running and on the completion of 5 Seconds, the app will be redirected to the home page.

Summary

Thus we saw how we can use a Timer Control to automatically navigate between screens, in our case, we navigated back from the Success screen to Home Screen after a 5-second delay.

Related Articles

Author

Author

Priyaranjan KS is a Modern Workplace Architect primarily focused on developing and architecting solutions around Office 365,Power Platform and Azure.He is also a Microsoft Most Valuable Professional(MVP) and a Microsoft Certified Trainer(MCT)

Latest Articles