When app runs in PowerApp Studio or Web, OnStart event does not fire. The reason is in PowerApp Studio or Web, app runs in Preview mode and OnStart is not supported in Preview. OnStart event only fires when app is launched in mobile/tab.
But to test your functionality on OnStart event, you can always add a button and define same action/step on OnSelect event of button.
I have a Pie Chart bind with a Collection to display Products by Company data. Since Collection data gets deleted when app is closed, I need to reload collection when app starts.
- I am using below code to load data into “ProductsByCompany” Collection. Let’s add this code to OnStart event of Browse Screen.
Collect(ProductsByCompany,AddColumns(GroupBy(AddColumns(‘Company Products’,”CompanyName”,cr2a5_Company1.cr2a5_companyname),”CompanyName”, “Products”), “ProductCount”, CountRows(Products)))
Please refer my blog to check what this code does.
- Run your app, you will see Chart does not show up when app starts. Reason is OnStart event of app does not fire in Preview mode and data will not be loaded into Collection to show up in Pie Chart.
- Let’s add a button on form. Give a name say “Collect”. Add above code in OnSelect event of button.
- Run your app, Press Collect button. You will see chart will load automatically as soon as you press Collect button.
Do not forget to remove/hide (set Visible property to false) button before publishing which we added for testing purpose.