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

Canvas app page lifecyle and onhidden

I am looking for some guidance regarding the OnHidden event.  When a user navigates away from the screen the OnHidden event fires.  Can the logic during that event still reference controls on the screen?  In testing this it appears as though all the controls are still available for evaluation during the OnHidden event.  I would like to add a patch to the OnHidden event that pushes all the values of the screen's control to a table.  I would just like to know if it's bad practice to do so in the OnHidden event.  I cannot find any guidance one way or the other in my research.

 

The two reasons I'd like to patch during the OnHidden are:

1: users don't want to click a save button.  They want what is essentially an auto-save on each screen.  When they navigate away, any data entered, if valid, should patch.  Any invalid data and they can't navigate away until the errors are corrected.

2: some controls load with default values that the user may not change.  Those values still need to patch to the database.

 

Thanks in advance for the help!

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@dallenap 

Screen and controls are global to the app.  They are always referenceable. OnHidden is just an action behavioral formula you can use when the screen is no longer the active screen.  The screen still exists (and all control) it is just no longer active.

So, in other words, you can look at the two Actions - OnVisible and OnHidden as OnActive and OnNotActive respectively.

 

As for your specific points:

1) Yes, this is done all the time.  Keep in mind forward screens...meaning, a lot of times on a screen you will navigate to another screen to fill out some other data or something.  Then when done, going Back() to the screen you are referring to.  Just keep in mind in that scenario, the OnHidden will occur then too.

 

2) Always consider your controls to have an input and an output.  The input is the record data you want in them, and the output is what you want to write to your datasource.  Too often people will try and create variables or collections to hold the values of the controls so they can then write them back...this is NOT needed and is just wasted typing time.  The controls are your values.  Use their output as the next input to your datasource writing.

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

2 REPLIES 2
Feiteira
Resolver II
Resolver II

Hi there @dallenap,

 

You could use the default behaviour of each component in that Screen, because, unless you are using the Reset() function or the actual Reset property of each component, the values will remain available until you close the browser tab or refresh the page.

 

Having that said, I think you idea is a better practice than just letting the values set still. As a plus, I suggest you insert a Timer and every minute or so, you could Patch() those values (assuming all your conditions are met).

 

Let me know if I can help you in any way 😀

RandyHayes
Super User
Super User

@dallenap 

Screen and controls are global to the app.  They are always referenceable. OnHidden is just an action behavioral formula you can use when the screen is no longer the active screen.  The screen still exists (and all control) it is just no longer active.

So, in other words, you can look at the two Actions - OnVisible and OnHidden as OnActive and OnNotActive respectively.

 

As for your specific points:

1) Yes, this is done all the time.  Keep in mind forward screens...meaning, a lot of times on a screen you will navigate to another screen to fill out some other data or something.  Then when done, going Back() to the screen you are referring to.  Just keep in mind in that scenario, the OnHidden will occur then too.

 

2) Always consider your controls to have an input and an output.  The input is the record data you want in them, and the output is what you want to write to your datasource.  Too often people will try and create variables or collections to hold the values of the controls so they can then write them back...this is NOT needed and is just wasted typing time.  The controls are your values.  Use their output as the next input to your datasource writing.

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (4,046)