cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Advocate I
Advocate I

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
Highlighted
Dual Super User III
Dual Super User III

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.
Highlighted
Frequent Visitor

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.

Highlighted
Dual Super User III
Dual Super User III

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.
Highlighted
Advocate I
Advocate I

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

Highlighted
Dual Super User III
Dual Super User III

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
Advocate I
Advocate I

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. 

 

Highlighted
Advocate I
Advocate I

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
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Watch Now

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

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