Blog
Apps - Migrating OnStart formula to use App.StartScreen/ Fixing existing apps that implement deep linking
A recent update to Power Apps now prohibits the use of Navigate in App.OnStart. Existing apps that call Navigate in App.OnStart will show the error 'Navigate is not permitted in OnStart. Use the StartScreen property instead.' How do we fix this problem? The post describes some of the possible solutions.
The reason for this change is to prevent complex, long-running formulas in App.OnStart which can significantly slow the start up time of an app. Long running code in App.OnStart blocks the display of the first screen in the app which makes an app appear noticeably slower to a user.
Whilst the intention of this change is very beneficial, it causes difficulty for app builders with complex code on App.OnStart, typically, apps that implement some sort of deep linking functionality. This post describes the typical challenges and describes the possible migration techniques.
Why does deprecating the use of Navigate in App.OnStart cause a problem?
https://apps.Power Apps.com/play/c4c89866-5b53-4668-9a67-bd9e06ee56a0?IssueID=12
To adapt an auto-generated app to support this deep linking functionality, a fairly typical approach is to add the following formula to the OnStart property of the app.
If(Not(IsBlank(Param("IssueID"))),
Navigate(DetailScreen1,ScreenTransition.Fade),
Set(RecordSeen,true)
)
The Item property of this display form would be set to the following formula.
If(RecordSeen=true,
BrowseGallery1.Selected,
LookUp(Issue, IssueID=Param("IssueID"))
)
To configure the form to subsequently display the selected record in the gallery afterwards, we set the OnHidden property on the screen to the following formula.
Set(RecordSeen,false)
This overall technique will no longer work because it's not possible to call Navigate from App.OnStart. We now receive the error - 'Navigate is not permitted in OnStart. Use the StartScreen property instead.'
How exactly do we use the StartScreen property instead? Let's take a look at the possible migration methods.
Method 1 - Set the StartScreen property of the app
If(IsBlank(Param("IssueID")),
BrowseScreen1, DetailScreen1
)
This configures the app to display DetailScreen1 if the web address includes an IssueID value. If not, the app displays BrowseScreen1.
Method 2 - Set the StartScreen and disable the 'Use non-blocking OnStart rule'
If(Not(IsBlank(Param("IssueID"))), Set(varSelectedRecord,
LookUp(Issue, IssueID=Param("IssueID"))
);
Navigate(DetailScreen1)
)
If(Not(IsBlank(Param("IssueID"))), Set(varSelectedRecord,
LookUp(Issue, IssueID=Param("IssueID"))
);
)
If(IsBlank(Param("IssueID")),
BrowseScreen1, DetailScreen1
)
Therefore, it's possible for the app to display the start screen and to display the value varSelectedRecord.IssueDescription in the text input control before it successfully loads the target record in App.OnStart. In this case, the text input control will be empty, which is incorrect behaviour.
Method 3 - Use a timer control to run the startup formula
If(Not(IsBlank(Param("IssueID"))), Navigate(DetailScreen1,
ScreenTransition.Fade,
{locSelectedRecord:
LookUp(Issue, IssueID=Param("IssueID"))
}
)
Method 4 - Re-enable Navigate in App.OnStart through the settings
Conclusion
- Categories:
- formulas
- Calculations - What mistakes can happen when we fail to use round brackets correctly in calculations?
- Walkthrough - Solving maths puzzles with Power Apps
- Formulas - Review of how to write formulas using natural language
- Formula - converting centimeters/meters to feet and inches, and vice versa
- Dates - 4 tips to make sure that dates display correctly in UK "dd mm yyyy" format
- Formulas - How to calculate the distance between 2 points
- SharePoint - How to Patch the 6 most complex data types
- Formulas - Generating Row Numbers - Part 2
- Data - How to access nested collections/tables
- Formulas - Show Running Totals
- Formulas - Generating Row Numbers