Understand Variables | How to use variable in Canvas App? – Power App
Variables are used to store information to be referenced and manipulated. In Canvas App we have three types of variables. Lets look into it..! š
Types of variables:
Type | Variable Scope | Description |
Global variable | App | You can store (number, text string, Boolean, record, table, Etc.) value in this variable and access anywhere in your application. |
Context variable | Screen | You can store any value in this variable but you can make use of those variable only inside the screen. But you can pass this variable to different screen as a parameter value. |
Collection | App | Itās a complex type variable. Using this you can store Table, JSON, Etc. kind of values in this variable. |
Variable Scope:
All the variable values are held in memory until application runs. Once application got closed all the values will be erased.
When your application opens all the variable values were blank.
Functions:
- For Global Variable
- Use Set eg: Set(Name,ā365Stack.inā);
- For Context Variable
- Use UpdateContext eg: UpdateContext({Title:ā365Stack.inā});
- Use Navigate eg:Navigate(ScreenName,Title);
- For Collection
- Use Collect, ClearCollect. Eg: Collect(EmpData,{Name:ā365Stackā,Age:24}))
How to use it ?
Below screenshot will show some different way of using variables.
Set Variable On Button Select:
Using Variable In Textbox Default Property:
So once on button click value will be displayed in textbox. Refer above image for set variable.
Set Context Variable On Button Select:
Displaying Context Variable Using Label:
Load Collection On Button Select:
View Collection Data:
From setting page you can view data available in the collection variables.
View Global And Context Variable:
Check walkthrough video :