Hello Friends,
Welcome back with another post on PowerApps. We all know that we can define two types of variables in PowerApps-
- Global Variable:- These types of variables are defined using Set function. Scope of these types of variables is entire App.
Set(varGlobal001, "Global Variable 1")
- Context Variable:- These types of variables are defined using UpdateContext function. Scope of these types of variables is the same screen. These variables are not available on other screens in that App.
UpdateContext({varContextVariable:"Context Variable 1"})
But, if I say that you can access Context Variables on other screen to which you are navigating, then you will be surprised.
Yes, we can access the Context Variables on other screens as well. But there is a condition. Let me explain. We have Navigate function which is used to navigate from one screen to other. Everyone provides 2 values to this function-
- ScreenName (to which user has to be navigated)
- ScreenTransitionType (transition type of screen during navigation. i.e. None, Fade, Cover...)
Let's understand with an example.
- Create a PowerApp. By default Screen1 will be added automatically. Now add one more blank screen "Screen2".
- Navigate to Screen1 and add 2 labels, 2 input text boxes and 1 button.
- Now add below Navigate function on Button >> OnSelect property.
Navigate(Screen2,ScreenTransition.Fade,{varText1:TextInput2.Text,varText2:TextInput3.Text})
- Remember, till now, we haven't perform any activity on Screen2.
- Now, click on Screen2 and add 2 labels. Now change the Text property on these labels. The moment you start writing vart, it will populate both variables, we have defined on previous screen in Navigate function.
- Assign varText1 variable to first label and varText2 variable to second variable.
- You may add one button to navigate back to Screen1.
- Now save the app and play. Below are 2 screenshots. The first one is on Screen1 where I input "Hello" and "World" as input text to first and second textbox respectively.
- Now clicked on Navigate button. Second screen appears where first label is showing the value of first variable while second label is showing value of second variable.
- You may play with this by going back, changing the text box values and navigating again to Screen2.
- This way you can use Context Variables to pass information from one screen to other screen. Using this feature, you can remove dependency upon Global Variables, thus resulting the App performance.
With this, I am concluding this post.
Happy Coding !!!
Will see you again with some new topics.
Stay Safe !
Stay Healthy !
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.