cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
HFG
Level: Powered On

Variables not updating correctly OnStart

I have created one variable in App OnStart which houses various details about the colours and layout to be used in the app. 

 

When something is adjusted on the app, it's necessary to run OnStart various times before all the variables are taken into account, it's as if the app is only processing part of the code each time. 

 

When the App is published and launched, the layout is not correct either. 

 

Does anyone have any tips on how to correct this? 

 

Thanks

7 REPLIES 7
Super User
Super User

Re: Variables not updating correctly OnStart

When I've run into this before its normally been an issue of timing.  Its not that the variables don't get set, its just that the screen gets built before they are set. Try this.  Add a Splash screen to be the first screen loaded by your app with a timer to switch it to the old primary screen.  See if that delay doesn't help with the variables being applied.  Take a look at this post to see how to build a timer enabled splash screen.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
Surender
Level: Powered On

Re: Variables not updating correctly OnStart

I have tried settingup a avriable with couple of colors and then save and published. And then went to Apps list and ran the App from there it is taking my theme set from my Variable.

 

And then I changed variable colors and save and published, and then back to apps list and run the pulised app and it still showed old theme, then I closed and rerun the App and it took latest Theme. Might be caching issues. 

 

Try setting a label with your theme color. And change the name "Color" to something as this is a predefined one(might be due to ambiguity) is not letting to work it properly.

Super User
Super User

Re: Variables not updating correctly OnStart

OK, I did some more testing.  I would recommend the following change.  Move your code that sets variables from the OnStart for the app to the OnTimerStart for the timer on the Splash screen.  That appears to be much more reliable.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
HFG
Level: Powered On

Re: Variables not updating correctly OnStart

Hi, 

 

Thanks for your help, I'll give it a go. Could you provide the link to the post on how to build a timer enabled splash screen? I can't see it in the post above :-) 

 

Thanks

Super User
Super User

Re: Variables not updating correctly OnStart

Sorry, I meant to add that to the last reply.

https://ilovepowerapps.wordpress.com/2019/01/08/create-a-splash-or-a-wait-screen-in-powerapps/



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
Highlighted
HFG
Level: Powered On

Re: Variables not updating correctly OnStart

Hi, 

 

Thanks again for your input. Unfortunately, the timer didn't work. The problem seems to be coming from the fact that the variable makes reference to itself. It isn't calculating the values on the first run, but after a second or third run it catches up. The colour part is working fine as there is no reference to the variable. 

 

One solution I have found is to add the same code twice, either in the OnStart or once in OnStart and once in the OnTimerStart. This seems to give the app time to calculate each of the values correctly. 

 

However, for now I am going to seperate the variables, I think this will be cleaner than repeating the same code twice. 

 

HFG
Level: Powered On

Re: Variables not updating correctly OnStart

Thanks for your input. The colour part is actually working ok. The problem is with the layout and it seems to be because it makes reference to the same variable it is housed within. 

Helpful resources

Announcements
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

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

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

SecondImage

Power Platform Summit North America

Register by September 5 to save $200

Top Kudoed Authors
Users Online
Currently online: 166 members 4,185 guests
Please welcome our newest community members: