cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
guyinazo
Level 8

Setting inital variable

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

1 ACCEPTED SOLUTION

Accepted Solutions
Sienna
Level 10

Re: Setting inital variable

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

View solution in original post

11 REPLIES 11
Sienna
Level 10

Re: Setting inital variable

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(""))

 

Highlighted
Meneghino
Level 10

Re: Setting inital variable

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.

guyinazo
Level 8

Re: Setting inital variable

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
Level 10

Re: Setting inital variable

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:""})

guyinazo
Level 8

Re: Setting inital variable

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
Level 10

Re: Setting inital variable

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
Level 10

Re: Setting inital variable

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/8...

guyinazo
Level 8

Re: Setting inital variable

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?

Sienna
Level 10

Re: Setting inital variable

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

View solution in original post

Helpful resources

Announcements
thirdimage

Power Apps Super User Class of 2020

Check it out!

thirdimage

New Badges

Check it out!

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors
Users online (5,308)