cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
HFG
Advocate II
Advocate II

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

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

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.

Pstork1
Dual Super User III
Dual Super User III

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.

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

Pstork1
Dual Super User III
Dual Super User III

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.

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. 

 

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
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (3,095)