web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Setting a simple Globa...
Power Apps
Unanswered

Setting a simple Global variable Not working

(0) ShareShare
ReportReport
Posted on by 226

According to this documentation, developers should be able to set global variables anywhere. The documentation is either inaccurate or flawed (omitting an important detail). From the attached screenshot I am trying to do a simple global variable set. Set(VarN,2). When I test VarN, it's empty.

 

MS Documentation:

https://learn.microsoft.com/en-us/power-apps/maker/canvas-apps/working-with-variables

 

 

 

image.png
image.png
Categories:
I have the same question (0)
  • cha_cha Profile Picture
    4,932 Moderator on at

    Hello @jv123 

     

    Where and how are you initializing the variable? Variable values are initialized/updated when a specific event is simulated (examples: OnSelect, OnStart, OnSuccess)

     

    If you want the value to be set when the app is loaded, you should put it in App.Onstart property, like this:

    cha_cha_0-1670086233756.png

     

    But if you are in developing mode (not play mode), that will not take effect immediately as you need to simulate the Actual App.OnStart to assign a value. It can be done here:

    cha_cha_1-1670086285890.png

     

    If you did not trigger the property that initializes your value, it will remain null.  An example of this would be you set the value on an OnVisible or on an OnClick property, but there was no action yet made to simulate that event, then the value will be null.

     

    Also if you think that the explanation is misleading, scroll down to the bottom of the page so you can give feedback. This will get the attention of Microsoft and update it to something more appropriate.

     


      ✔️
    Just in case you my answer helped you solve your problem, please mark/accept this as a SOLUTION This helps community members if they experience a similar issue in the future.

     

      🔗
    🕸bistek.space  🐦 @cha_bistek  📺 @BisTekSpace 

     

  • jv123 Profile Picture
    226 on at

    It's initialized from an "OnSuccess" button action. I find this part of PowerApps to be inconsistent.  All other variables evaluate when testing but a direct assignment doesn't test out at all. Makes very little sense. From the additional screenshots I included, I am testing another variable in the same code block that doesn't use a direct "Set" function and it tests out just fine.

    image.png
    image.png
  • cha_cha Profile Picture
    4,932 Moderator on at

    Hello @jv123 ,

     

    Maybe you are right. Though still consider giving feedback to that Learn page so that it can be rectified by Microsoft.

     

    Also, here's a video of Shane Young about variables. It might be your quickest way to familiarise variable types with actual demonstration.

  • jv123 Profile Picture
    226 on at

    I've watched Shane's videos he's got outstanding tips and I posed a few questions for him in the past. I'm familiar with variables but rarely had to do direct assignment with "Set". 

  • Pstork1 Profile Picture
    69,197 Most Valuable Professional on at

    [@InputItem].Text isn't a variable.  Its a property of a control.  That's why they evaluate differently. The vaue of an actual global variable has to be established using the Set() command.  And the function needs to be executed before the value will be set.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 600

#2
WarrenBelz Profile Picture

WarrenBelz 478 Most Valuable Professional

#3
Valantis Profile Picture

Valantis 322

Last 30 days Overall leaderboard