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 / Variables not updating...
Power Apps
Unanswered

Variables not updating correctly OnStart

(0) ShareShare
ReportReport
Posted on by 524

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

AppOnStart code screenshot.PNG
Categories:
  • Pstork1 Profile Picture
    69,665 Most Valuable Professional on at

    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.

  • Surender Profile Picture
    24 on at

    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 Profile Picture
    69,665 Most Valuable Professional on at

    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.

  • HFG Profile Picture
    524 on at

    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 Profile Picture
    69,665 Most Valuable Professional on at
  • HFG Profile Picture
    524 on at

    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 Profile Picture
    524 on at

    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. 

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 248 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 192 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 135

Last 30 days Overall leaderboard