Skip to main content

Notifications

Community site session details

Community site session details

Session Id : 6u6MgAPzilso5WuHL0HQbq
Power Apps - Building Power Apps
Unanswered

Cannot Set Variable With OnSelect

Like (0) ShareShare
ReportReport
Posted on 8 Mar 2023 14:09:00 by 1,272 Super User 2025 Season 1

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?

  • WarrenBelz Profile Picture
    146,947 Most Valuable Professional on 08 Mar 2023 at 20:52:48
    Re: Cannot Set Variable With OnSelect

    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.

  • mmollet Profile Picture
    3,187 on 08 Mar 2023 at 16:57:29
    Re: Cannot Set Variable With OnSelect

    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.

  • IPC_ahaas Profile Picture
    1,272 Super User 2025 Season 1 on 08 Mar 2023 at 15:59:45
    Re: Cannot Set Variable With OnSelect

    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?

  • IPC_ahaas Profile Picture
    1,272 Super User 2025 Season 1 on 08 Mar 2023 at 15:58:25
    Re: Cannot Set Variable With OnSelect

    @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.

  • IPC_ahaas Profile Picture
    1,272 Super User 2025 Season 1 on 08 Mar 2023 at 15:49:56
    Re: Cannot Set Variable With OnSelect

    @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"

    IPC_ahaas_0-1678289991313.png

    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:

    IPC_ahaas_1-1678290441397.png


    The buttons do nothing...

     

     

  • mmollet Profile Picture
    3,187 on 08 Mar 2023 at 15:25:07
    Re: Cannot Set Variable With OnSelect

    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? 

  • mmollet Profile Picture
    3,187 on 08 Mar 2023 at 15:19:42
    Re: Cannot Set Variable With OnSelect

    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. 

  • RJM07 Profile Picture
    801 on 08 Mar 2023 at 15:08:18
    Re: Cannot Set Variable With OnSelect

    Global Variables

    RJM07_0-1678288055303.png

    Local Variable

    RJM07_1-1678288091391.png

     

     

  • IPC_ahaas Profile Picture
    1,272 Super User 2025 Season 1 on 08 Mar 2023 at 15:08:08
    Re: Cannot Set Variable With OnSelect

    I tried it and have the same experience. 

  • RJM07 Profile Picture
    801 on 08 Mar 2023 at 15:06:28
    Re: Cannot Set Variable With OnSelect

    See I don't actually know, but that's what I was told... done it ever since and never had an issue 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Apps - Building Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 89 Most Valuable Professional

#2
MS.Ragavendar Profile Picture

MS.Ragavendar 60

#3
stampcoin Profile Picture

stampcoin 48

Overall leaderboard