I want to navigate to a new screen and get a value from the calling screen to filter a specific record on that new screen. Most examples (including 'Start from data') filter a record with the selected item from a specific gallery (on a specific screen) with:
BrowseGallery1.SelectedHowever I want to call this screen from various calling screens (not just one). Is there a push meganism instead of a pull meganism to filter the record on the new screen?
Navigating to a new screen from various screens |
Solution
The solution is to pass a value from the calling screen to the new screen. The Navigate function has an optional argument called 'UpdateContextRecord' which allows you to pass a record to the new screen which on its turn updates the context variable on the new screen. Then you can use that variable to filter a specific record.
1) Calling screen(s)
In PowerApps a record with one column (a variable) looks like:
{myIntColumn:123}
If you put this in the 'UpdateContextRecord' argument from the Navigate function it looks like:
Navigate(myNewScreen, ScreenTransition.None, {myIntValue:123})
The hardcoded '123' should of course be replaced with some code to get the value from a gallery column on the calling screen. The Value function converts the string to a number:
Navigate(myNewScreen, ScreenTransition.None, {myIntValue:Value(ThisItem.myIntColumn)})
You need to repeat this on all calling screens that want to navigate to this new screen.
2) New screen
On the new screen this record will be pushed to a new context variable which can be used in for example a LookUp function in the Item property of a form:
LookUp('[dbo].[myTable]', myIntColumn=myIntValue)
Changed from pull to push |
Alternative form item formula:
First(Filter('[dbo].[myTable]',myIntColumn= myIntValue))Conclusion
In this post you learned how to pass through variables from one screen to an other. This can be used to pass through values for filters from several screens instead of just reading values from one screen.