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.

 

2 ACCEPTED SOLUTIONS

Accepted Solutions

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.

 

Hope this helps

Gerard

View solution in original post

@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?

 

View solution in original post

11 REPLIES 11
WarrenBelz
Super User
Super User

Hi @Walad100100 ,

I assume you did not have the quotes around it

Set(
   myVar,
   100
)

certainly should work both at App OnStart and Screen OnVisible.

AmDev
Super User
Super User

Hi @Walad100100 

 

Just a quick one also, if you are in Power apps studio to make sure you run onstart as follows to initialise the variable. Right click on the App and Run OnStart..

 

AmDev_0-1653649812806.png

 

Of course without quotations. It is not working for sure -- try it!

Please note that 

 

Set(var01, 1000)

 

works in OnSelect of a button!

 

Try it with a blank Canvas app -- you will find that it does work in OnStart nor OnVisible . Very frustrating!

I should "Run OnStart" manually?!

What's gonaa happen to the app when I share it with the users in production?

Why Playing the app doesn't run OnStart properly?

Why OnVisible doesn't execute Set(var01, 100) properly?

 

It doesn't make any sense -- Very odd and disappointing (unless I am missing something).

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.

 

Hope this helps

Gerard

@AmDev Trust me, I understand what you are saying and that's what SHOULD be. But if try it NOW, it won't work! (give it a shot!).

 

I really appreciate your help as I need this to work badly.

@Walad100100 ,

Please believe @AmDev and myself here - it is a basic variable  - I set dozens of Variables at App OnStart and Screen OnVisible in my apps. I did a test on both as below and ran the app OnStart and Screen OnVisible as below

 

WarrenBelz_1-1653685981866.png

WarrenBelz_2-1653686034036.png

If what you are seeing was normal behaviour, Power Apps would be very broken for everyone.

 

 

 

AmDev
Super User
Super User

@Walad100100  the only other thing I can think of is you have not published the app which has your updates to the onstart property?

@Walad100100 ,

I think @AmDev has it here - I certainly cannot think of any other reason this would be happening

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,991)