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 inital variable
Power Apps
Answered

Setting inital variable

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

I use an app with a local variable and want to set that variable to NOTHING or NULL or "" (not sure which to use yet) on the start of the application. I put this varForm="" in the OnStart and it did not do anything.  I then put it in the OnVisible and still did not do anything.  Where in the properties should this go and is there such as thing as thisVar=NOTHING?

 

Thanks

Categories:
I have the same question (0)
  • Sienna Profile Picture
    1,532 on at

    I'm afraid you will have to give us more information about the variable. If the variable is is used in your app as numeric and in one page then use

    UpdateContext({varForm:0}); UpdateContext({varForm:Value("")})

    or if the variable is in text format and used in one screen

    UpdateContext({varForm:" "}); UpdateContext({varForm:""})

    or in case the variable is global used in multiple pages set as text

    Set(varForm," "); Set(varForm,"")

    or in case the variable is global used in multiple pages set as numeric

    Set(varForm,0); Set(varForm,Value(""))

     

  • Meneghino Profile Picture
    6,949 on at

    The OnStart will fire only once when the app is opened, hence you need to modify the property then save, close and re-open the app for it to work.

    Nulls are a pain in PowerApps, please see this post.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Sienna,

     

    It is a text variable.  I have only one screen and one form, but based on a few different buttons, I am showing or hiding different data cards and I want the app to always begin with the "Personal" tab (or button).  I tried using UpdateContext, but got an error about it being a global variable.  So I tried using Set(varForm,Value"")) and it gives me Invalid Argument Type.  However, if I do Set(varForm,Text("")) it seems to work, but when I run the app it does not reset the variable's value.

  • Sienna Profile Picture
    1,532 on at

    Therefore you have to reset it with other value as I wrote it above. 

    Set(varForm,Text("whatever"));Set(varForm,Text(""))

     

    But if you using it in one screen then use UpdateContext !!!!

     

    UpdateContext({varForm:"whatever"}); UpdateContext({varForm:""})

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    It is interesting that the app only uses one screen and I am trying UpdateContext again, but it is giving me an error about the variable being global.  So I am using Set(varForm,Text("Personal"));Set(varForm,Text("")) and it does not error, but it is not setting the variable either and retaining a prior value.  

     

    Ultimately what I want is when the app opens, set the variable to the text value "Personal" and show those data cards whose visible property is true when varForm value is "Personal".  I want a new user opening the app to land on that screen each time.

  • Sienna Profile Picture
    1,532 on at

    It is interesting that the app only uses one screen and I am trying UpdateContext again, but it is giving me an error about the variable being global.

    That is because you have somewhere in your app used that variable and seting it with "set" funftion

    So I am using Set(varForm,Text("Personal"));Set(varForm,Text("")) and it does not error, but it is not setting the variable either and retaining a prior value

    Send a picture of your tab gallery with all your code in it and a datasource link to your tab to be able to help you more with this issue

  • Sienna Profile Picture
    1,532 on at

    meanwhile you can check this thread for default selecting the tab 

     

    https://powerusers.microsoft.com/t5/General-Discussion/Select-a-Gallery-item-on-screen-visible/m-p/80564#M31413

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    RMEQ Tabs.PNG

     

    This is a snip of the "tool bar" I am using.  What I am trying to do is avoid using a PATCH statement.  Recently I saw someone use this "tab" environement and one screen and one form to show and hide datacards.  The dataset is a Sharepoint list.  

     

    When a button is selected, I am using the OnSelect in this context: Set(varFormTab="Personal") for the btnPersonal; Set(varFormTab="Medical") for the btnMedical, and so on.  So yes, I am using the Set keyword.  Should I use UpdateContext instead?

  • Verified answer
    Sienna Profile Picture
    1,532 on at

    If you are using it in one screen then definitely change it witch local variable that means UpdateContext with proper syntax as I mentioned it above

    UpdateContext({varFormTab:"Personal"})

     

    And remove all your set function because you have wrong syntax there

    Set(varFormTab="Medical") - is wrong syntax

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Thank you.  This seems to work

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 April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 834

#2
Valantis Profile Picture

Valantis 533

#3
Haque Profile Picture

Haque 410

Last 30 days Overall leaderboard