cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Walad100100
Frequent Visitor

Global Variables not initialized in App.OnStart nor OnVisible

My App.OnStart has the following single statement:

 

"Set(myVar, 100)"

 

After running (playing) the app I saw the "myVar" in under View/Variables but with "No Value" assigned to it. 

 

I put the same code in the screen under OnVisible and got the same result, i.e., the "myVar" did not get initialized!

Your help, please.

 

11 REPLIES 11

@WarrenBelz @AmDev Thanks for the sincere effort. 

I think I discovered what is going on. It all goes down WHEN OnStart and OnVisible get triggered in Power Apps. I was believing that when I click the Play button to run the program OnStart should start. That does not happen. OnStart is triggered when the app is "loaded" only. For that reason, MS provided the manual option "Run OnStart".

 

Similarly, OnVisible of the start screen won't work (does not get triggered!) UNLESS I am on another screen and I navigate back to it or when loading the app for the first time. 

 

I learned about all the above in the hard way -- I do not believe the documentation spells it out. 

 

I think that Power Apps are still not happy with the OnStart and they are trying to improve it progressively:

https://docs.microsoft.com/en-us/power-apps/maker/canvas-apps/functions/object-app#onstart-property 

 

Any pointer to learn about the run-time management, execution, and memory model of Power Apps?

 

Hi @Walad100100 

 

This behaviour in the app was relayed as part of the following post earlier in this thread:

 

@AmDev wrote:

Hi @Walad100100 

 

The app.onstart property runs when the app starts in both play mode and when you open it in edit mode. The manual run onstart button is there to help if you want to check any changes you make to the onstart property while working on the App (avoiding the need to launch the app in play mode to check your changes). For end users, App.onstart will run when they launch the app.

 

The onvisible expression for your landing screen is triggered when you start the app in either play or edit mode, and again if you make a change to the expression while in editing the app, the way to trigger it is to move to a different screen and then come back to your landing screen and that will re-trigger the onvisible on the landing screen. For end users, onvisible will be triggered for all screens they navigate to.

 


Though, glad you got sorted in the end 👍

 

You can find some tips on optimising performance here: Tips and best practices to improve performance of canvas apps - Power Apps | Microsoft Docs 

 

There's an abundance of documentation on power apps if you navigate from the above link to topics relevant to you.

 

If you have a specific question on runtime management after having reviewed the documentation, I would  recommend coming back on the forum and raising another thread.

 

Good luck

Gerard

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on June 15, 2022 at 8am PDT.

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Top Kudoed Authors
Users online (2,734)