How to Use App OnStart Function in Power Apps?

This Power Apps tutorial will teach us about the Power Apps OnStart Property. Then, We will discuss how to use app OnStart function in Power Apps.

Moreover, we will discuss how to use the StartScreen property in Power Apps and set the global variable in Power Apps OnStart property.

Also, we will create a Power Apps collection using the Power Apps OnStart property by taking a simple scenario.

Power Apps OnStart Property

  • Power Apps OnStart Property runs when the user starts a Power Apps app.
  • The OnStart property in Power Apps is broadly used to initialize a global variable, cache, or retrieve data from the collection.
  • Microsoft recently announced that the “Navigate()” function in the Power Apps OnStart property is deprecated. To resolve it, you should use a new property named “StartScreen“.
  • Previously, when we used the Navigate() function in the Power Apps OnStart property, the app would be loaded very slowly to show the screen until all the code logic was executed successfully.

Note:

Power Apps OnStart property may be disabled by default depending on your performance reasons. If you want use it then, check the App’s “Advanced settings” for a switch to enable it.
OnStart Property in Power Apps

How to Use App OnStart Function in Power Apps

Here, we will discuss how to use the OnStart property in Power Apps.

  • For example, I have created a Power Apps Canvas app. Inside this app, I have added three different screens, i.e.,
    • WelcomeScreen
    • EmployeeRegistrationScreen
    • SuccessScreen
How to Use OnStart Property in Power Apps
How to Use OnStart Property from Power Apps
How to Use a OnStart Property in Power Apps
How to Use a OnStart Property from Power Apps
  • Whenever we run a Power Apps app, it will always start with the default/first screen. I want to run the app with the second screen [EmployeeRegistrationScreen] by using a Navigate() function in the OnStart property.
  • But, unfortunately, I will get an error message, i.e., [Navigation is not permitted in OnStart. Use the StartScreen instead] like below.
How to Use the OnStart Property from Power Apps
  • To resolve this problem, I have used the “StartScreen” property to navigate the second screen. Now, whenever I start or run an app, it gives a second screen, as shown below.
How to Use a ScreenStart Property in Power Apps

To work around the above example, follow the below-mentioned steps. Such as:

  • Open your Power Apps with respective Microsoft credentials -> Create a Canvas app where you want to add different screens -> Click on the App object [From left navigation] -> Select StartScreen and set its property code like below.
StartScreen = EmployeeRegistrationScreen

Where,

  1. EmployeeRegistrationScreen = Second Screen
OnStart Property in Power Apps
  • Then, click on the App object -> Select More commands (…) option -> Click on the Navigate to StartScreen button.
  • Next, Save and Publish the app -> Click on the Apps section -> Select the respective Canvas app [Power Apps OnStart Property] -> Click on the Play icon under the More command (…) option like below.
How to Use OnStart Property from Power Apps Canvas app
  • Once you select the Play icon, it will run with the second screen, as shown below.
Power Apps OnStart Property

This is how to use the OnStart property in Power Apps.

Power Apps Set Global Variable OnStart

Let us see how to set global variables using Power Apps OnStart property.

  • For example, I have created a table using a global variable [gvProducts] on the Power Apps OnStart property. There are five columns in the table:
  1. ProductName
  2. Category
  3. Price
  4. Color
  5. Quantity

Refer to the below table:

ProductNameCategoryPriceColorQuantity
Office ChairOffice1500Brown5
Dining TableHome1000Red10
Baby FurnitureChildren900Blue15
Bowls and FeedersPet Furniture1000White25
Set Global Variable Using Power Apps OnStart Property

To achieve the above example, follow the below steps.

  • On the Power Apps Screen -> Click on the App object [From left navigation] -> Select OnStart and set its property code like below.
OnStart = Set(
    gvProducts,
    Table(
        {
            ProductName: "Office Chair",
            Price: 1500,
            Category: "Office",
            Quantity: 5,
            Color: "Brown"
        },
        {
            ProductName: "Dining Tabel",
            Price: 1000,
            Category: "Home",
            Quantity: 10,
            Color: "Red"
        },
        {
            ProductName: "Baby Furniture",
            Price: 900,
            Category: "Children",
            Quantity: 15,
            Color: "Blue"
        },
        {
            ProductName: "Bowls and Feeders",
            Price: 1000,
            Category: "Pet Furniture",
            Quantity: 25,
            Color: "White"
        }
    )
)

Where,

  1. gvProducts = Global variable Name
  2. ProductName, Price, Category, Quantity, Color = Table Headers/ Columns
  3. “Office Chair”, 1500, “Office”, 5, “Brown” = Table Values/ Rows
Set Global Variable Using a Power Apps OnStart Property
  • Next, click on the More commands () option and click on the Run OnStart option to get our global variable.
  • Then, go to the Variables section (x) -> Select Global Variables drop-down to find the product table like below.
How to Set Global Variable Using Power Apps OnStart Property
  • Also, if you want to see your created global variable, i.e., [gvProducts] then, click the View Table option to view all the records as shown below.
How to Set Global Variable Using a Power Apps OnStart Property

This is how to set a global variable using the Power Apps OnStart property.

Create a Collection Using Power Apps OnStart Property

Now, we will discuss creating a collection using the Power Apps OnStart property.

  • Suppose I have created a Power Apps collection, i.e., [AirlineCollection] using the OnStart property. There are two columns in the table:
  1. AirlineName
  2. EstimatedAirfare

Refer to the below table:

AirlineNameEstimatedAirfare
Alaska Air$167,791
Southwest$99.7
British Airways$28,365
Emirates$13,437
Create a Collection Using Power Apps OnStart Property

To work around the above example, follow the below steps.

  • On the Power Apps Screen -> Click on the App object [From left navigation] -> Select OnStart and set its property code like below.
OnStart = ClearCollect(
    AirlineCollection,
    {
        AirlineName: "Alaska Air",
        'EstimatedAirfare': "$167,791"
    },
    {
        AirlineName: "Southwest",
        'EstimatedAirfare': "$99.7"
    },
    {
        AirlineName: "British Airways",
        'EstimatedAirfare': "$28,365"
    },
    {
        AirlineName: "Emirates",
        'EstimatedAirfare': "$13,437"
    }
)

Where,

  1. AirlineCollection = Collection name
  2. AirlineName, Estimated Airfare = Table Headers/ Columns
  3. “Alaska Air”, “$167,791” = Table Rows/ Records
Create Collection Using Power Apps OnStart Property
  • Next, click on the More commands () option and click on the Run OnStart option to get our collection.
  • Then, go to the Variables section (x) -> Select Collection drop-down to find the collection table like below.
Create Collection Using a Power Apps OnStart Property
  • Also, if you want to see your created collection, i.e., [AirlineCollection], click the View Table option to view all the records below.
Create Collection Using the Power Apps OnStart Property

This is how to add a collection using the Power Apps OnStart property.

Also, you may like some more Power Apps tutorials:

Conclusion

This Microsoft Power Apps tutorial taught us about the Power Apps OnStart property. Then, we discussed how to use the OnStart property in Power Apps.

Also, we learned why the Navigate() expression is deprecated in a Power Apps OnSatart property and how to use the StartScreen property in Power Apps.

Finally, we covered how to set global variables in the Power Apps OnStart property and create a Power Apps collection using the Power Apps OnStart property.