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

Notifications

Announcements

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 224

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

 

 

 

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

  • 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
    224 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
    68,717 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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 765 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 272

Last 30 days Overall leaderboard