In my App > OnStart, I have Set(ShowDowntime,true); and I have a Text Label showing ShowDowntime which says "false".
I created three buttons to try and change ShowDowntime to true:
Button > OnSelect > Set(ShowDowntime,true);
Button > OnSelect > UpdateContext({ShowDowntime:true});
Button > OnSelect > Set(ShowDowntime,Not ShowDowntime);
None of these are setting ShowDowntime to true.
What am I doing wrong?
Hi @mmollet ,
You have summarised it well - UpdateContext sets a variable on the current screen and it is only valid on that screen - it will still be there when you come back as well and you can actually have variables with the same name on different screens with different values. Set is a Global Variable that applies throughout the app. I use gbl for Global and var for Context, but it really does not matter as long as you have a naming convention.
That is very strange tbh. Maybe its a save and close browser and try an incog browser and see if it works when you have a fresh session and Power Apps is fresh as well. Sometimes it gets confused and needs a break xD
edit: just saw the post on the second page of this thread. Maybe it has something to do with scope. By that I mean that since a form is essentially an object of the list (same as a class where each row is an object) used to create it, maybe it has its own scope and that caused your issue. One would think that the global var created using the set function would have been the fix for that. I would have to do some testing but that is my guess.
So the issue is that these objects exist within a Card within a Form. When I put them outside of the Form, they work!
Why would this stop the buttons from working? I have a ton of input fields so I thought Form was the only way to accomplish a scrolling list of them. Is there another way?
@mmollet wrote:UpdateContext > Creates Local Variable only visable to the screen it was created in (prefix loc to make it clear)
Set > Creates a Global Variable that is visable to any screen in the entire app (I assume prefix of glob or something)
That's good to know. I did verify that VarShowDowntime is a Global Variable.
@mmollet wrote:One thing about setting an onStart variable is that when you are developing your app is neve[r] actually 'starting' so that line is not executed.
Right, unless you click "Run OnStart"
I've used the Set function in another app flawlessly, I don't know why this app is struggling.
This is what I have right now as my test:
The Text label is:
"VarShowDowntime: " & VarShowDowntime
I have the buttons showing what the OnSelect values are:
The buttons do nothing...
I have never heard of, seen, or done this before in any App. Quick search on google shows nothing about this either. I think the person that said this was just trying to point out the fact that:
UpdateContext > Creates Local Variable only visable to the screen it was created in (prefix loc to make it clear)
Set > Creates a Global Variable that is visable to any screen in the entire app (I assume prefix of glob or something)
@WarrenBelz @Drrickryp You 2 are the goats on here it seems so figured I would loop you in and get a final answer on this. Loc/Var as a prefix of a variable name maybe be a personal standard but is not an actual function given by Power Apps correct?
One thing about setting an onStart variable is that when you are developing your app is neve actually 'starting' so that line is not executed. Generally I make a button that just says init and is only visable to me. This will run anything that I put in the onStart property of the app and then when I am done developing I just remove the button. If you are testing from a phone/tablet/pc and are actually running the app then this shouldn't be an issue.
That being said im not sure why your first 2 formulas aren't changing the variable as the syntax looks correct. The third one needs Not(ShowDownitme) instead of Not ShowDowntime as 'Not' is a function and so requires () when called.
I was just able to recreate this using: (only diff is I don't have onStart statment but that shouldnt't make a diff)
Button > OnSelect > UpdateContext({testingVar1: true});
Button > OnSelect > Set(testingVar2, false);
TextBox > Text > "var1: " & testingVar1 & ", var2: " & testingVar2
Both values started as false as expected and were changed to true when buttons were pressed.
Sometimes I have to save and just reload the browser as Power Apps just forgets what is going on it seems. This is rare but when it happens it usually costs me 20 min of looking around for an issue that doesnt exist. Maybe check var names and make sure you aren't displaying one value while changing another on accident. I have done this before as well.
Global Variables
Local Variable
I tried it and have the same experience.
See I don't actually know, but that's what I was told... done it ever since and never had an issue
WarrenBelz
89
Most Valuable Professional
MS.Ragavendar
60
stampcoin
48