Power Apps Variables: Global vs. Context and what you need to know

preview_player
Показать описание
Do you want to learn how to use Power Apps variables properly? Do you have no idea what a Global Variable is or a Context Variable? Can you use variables but sometimes get really confused why you can't make it blank or why you are seeing weird errors? Then this is the video for you. In this video, you will learn all about PowerApps variables, the differences, the performance considerations, troubleshooting, and how to update them throughout your app. All things Power Apps variables now in one updated video.

0:00 Power Apps Variables
1:43 Creating your first Power Apps Variable, a global variable, using the Set function
6:36 Creating a context variable in Power Apps using the UpdateContext Power FX function
10:40 Naming your variables to avoid confusion. How I do it vs. how most other people do it.
12:25 Creating multiple variables in PowerApps and how it is different with context vs. global variables
13:43 PowerApps Variables can be self referencing
16:02 You cannot mismatch your variable data types Error Incompatible Type
17:20 Setting a variable to blank
18:13 Finding and replacing variables in your app

Рекомендации по теме
Комментарии
Автор

Hey Shane,

Great video refresher on global vs context variables.

One trick I have been using regarding context variables if I really need it's value on a different screen and don't want to use a global: passing a context variable to another screen using the navigate function.

I had a scenario where I needed to pass a month value from a dropdown to another screen that also had a month dropdown dialog box so the user would have that month already selected on that screen.

Navigate(‘Screen2’, None, {varSelectedMonth: dropdown1.selected.value}) – the navigate function allows us to pass one or multiple context variables to another screen.

brendanbowen
Автор

Hi Shane, Great refresher. One tip I would add (for folks who are not color blind), Global variable names show up in green when referenced and context variable names show up in blue :)

samadjei
Автор

I now prefix variables as gvarName for globals and cvarName for context variables. No more broken brain cells.

GroverParkGeorge
Автор

Microsoft recommend prefixing local variables with loc and global variables with gbl. I think it's a really good idea. Having them both as var is a bit dangerous, imo. Fine for small apps, but might cause confusion in a big app.

charlessexton
Автор

We should start a support group: GVA (Global Variables Anonymous). I used to use the heck out of them because I thought I needed to. Nowadays, I typically use record variables (e.g.: Set(varO365Prof, and then reference components of that record as needed throughout the app. This works great for user profiles, items from galleries, etc. and helps cut down some of the chatter back and forth.

Also, a naming convention is important. Use what works for you, but I always use the prefixes "var" for global and "ctx" for context variables.

cvkealey
Автор

Hi Shane,

Thanks so much for providing information and tips regarding variables. I have a question. So basically what i want to do is create a form where the user will input information in various screens. So screen 1, they will enter information, then screen 2 they will enter information and keep going upto screen 5. Now what i want to do is take all those entered information and store it into a file as a single row item in Excel. This is ROW 1 items. Then a new user comes in enters new information and then this creates ROW 2 data in the same file. I searched around and got help from CHAT GPT, it said to do it using Variables and store information in variables and use it to export data into excel. Could you Shed some light into this scenario, or if you could help me out that would be greatly appreciated. Thank you.

zainraza
Автор

I feel you made this just for me! Thanks Shane! :-)

cbtjoe
Автор

Hi Shane - great vid, thanks. Another cool feature of context variables is they can be initiated on screen navigation (i.e. created on Screen1 but utilised in the screen being nav'd too). One thing i also would love to get a better understanding of is use of Variables in storing whole tables of records - i know this is what Collections are for (another variable type) but i'm pretty sure you can also do this in glb variables (not sure on Context variables tho). Cheers again

TheKermit
Автор

How do you set global variables on start-up, rather than tying them to buttons?

MatthewAyres-xoty
Автор

Shane, very clear! Thanks a lot for sharing your knowledge!

taaee
Автор

Really nice review of the world of variables. And you are the one to blame for me not using contextual variables 😂😂😂😂😂😂

franknielsen
Автор

Do you need to reset the context variables (set them to blank) if you are leaving the screen and then you want to come back to the same screen again, or will they reset themselves?

chriszielazny
Автор

Just made my day!! Been suck and I could tell I needed a variable but wasn't sure how, and boom, I'm fixed! Thank you!

vidabailey
Автор

Thanks Shane - another great vid.
Is it possible to use this global variable to change all of the app font size?

damianjohnson
Автор

It's okay context variables...I'm here for you. 👨‍💻

khargos
Автор

Hi Shane, is it possible to add a global variable so that a button on the main screen is hidden, until say, three other screens are visited?. I tried adding a global variable to onvisible for the secondary screens, but nadda. :(

dwolfe
Автор

Hi Shane,
I am struggling with how to set a global variable when the app first loads. I have a boolean variable (varShowInfo) that I use as the value of a label's visible property. The variable needs to start always with the value false. I have tried placing a Set(varShowInfo, Boolean(false)) in many places to no avail. I put it in the App OnStart event, but that only seems to execute if in the treeview, I select the ellipsis for App and click RunOnStart. That would be fine if it ALWAYS ran the OnStart when the App is started. Any help on this would be greatly appreciated.

Great videos!

Thanks

hokemspitter
Автор

Hi shane, I wonder if you could help me..
I have a dropdown with onchange value "UpdateContext( { varwl: 1 } )", -it helps me detect if there's a change
then if the user submits a button, with "UpdateContext( { varwl: 0 } )" - resetting it back to zero

it is not working very well, sometimes it work sometimes not, , , , it seems weird, , , escpecially when I get back to edit mode, varwl still display 1 even if i hit the button which should be reset to 0. any thought?

jodznolasco
Автор

You often say not to reference gallery1.selected but to store the reference as a variable instead. What would that variable look like? (Link to video?) Thx for the helpful Blank() tip!

geralddahl
Автор

Thank you so much Shane. New knowledge learnt

oluwatobiyusuf