web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / SaveData when app is c...
Power Apps
Unanswered

SaveData when app is closed to be reloaded when app is reopened

(0) ShareShare
ReportReport
Posted on by

Hello Community,

 

I made a mobile app that has a timer for registering how much time is spent on one task. The app has a SharePoint site Data Base and all info's are 'uploaded' there.

CristianF_0-1643812529570.png

CristianF_1-1643812745672.png

What i want (and I know this is possible but I couldn't find a working solution for me) is that when a task is running and time is registering, if the user will close the application, the app should automatically save current session and timer should still run some where in background and when he reopens the app to automatically have the data and timer reloaded until he will press 'Stop' button.

 

Will appreciate any help!

Best Regards,

CristianF

Categories:
I have the same question (0)
  • RandyHayes Profile Picture
    76,297 Super User 2024 Season 1 on at

    @Anonymous 

    You will not have timers continue to run in the background when closed.  

    However, your approach to the timers is a little backward.  Instead of using a timer to try and determine duration, instead record the start time of a timed event - either in the datasource or on the device (where you can also utilize the SaveData and LoadData if needed).

    Then, use the current time and the recorded time to determine the duration.  This way, even if the event started days ago, the duration can still be calculated based on the current date/time.

     

    I hope this is helpful for you.

  • Community Power Platform Member Profile Picture
    on at

    Hello @RandyHayes, many thanks for replying !

    Ok, understood that timers cannot continue run in background and this won't be such a big problem. I already have in place a calculated duration in place on stop button (timer display is shown on screen only for users 'knowledge', but not a must).

    CristianF_0-1643815917210.png

    Could you please be kind and show me on my example how can i use SaveData and LoadData (on what buttons and how should be formulated) since i already tried by my selve and i was not able to make it work...

  • RandyHayes Profile Picture
    76,297 Super User 2024 Season 1 on at

    @Anonymous 

    Well first, keep in mind that SaveData and LoadData function will only operate on the mobile device.  You cannot use them when you are designing as you will be designing your app in the browser.

    Technically, since you are storing the starttime in your datasource, then you don't really have to store that value in the device.  However, how you "recall" the data when the app starts again is totally dependent on how you are associating the start time with the current user.

    So you have any such association?

  • Community Power Platform Member Profile Picture
    on at

    @RandyHayes 

    I think the datasource it self could be the association...

    When a task button is pressed it's already "uploading" in datasource:

    ID, User, Shift, Start Time, Task and marking Active Session.

    CristianF_0-1643878252908.png

    CristianF_1-1643878384066.png

    And then only after Stop button is pressed it fills the remaining collumns End Time and Time Spent and also removes 'check' mark from active session.

    CristianF_2-1643878497361.png

     Maybe some sort of condition can be setted if user is loggin in the app and in datasource there is still a open active session under his user name and retake the session ?  

     

  • RandyHayes Profile Picture
    76,297 Super User 2024 Season 1 on at

    @Anonymous 

    Yes, in that picture, my design suggestion would be this.

    When your app starts, get the records for the user that have NO end time (or where active session is true).

    Then in your gallery of buttons, visually indicate the task that is still open.

    The user can then select that to stop is - in which case the End time is entered and the duration calculated.

     

    That would work pretty easily.

  • Community Power Platform Member Profile Picture
    on at

    @RandyHayes 

    Could you please help me with formulation ? It's my first time using powerapps and i've been trying for couple of hours and couldn't manage to find correct path of doing it...

  • Community Power Platform Member Profile Picture
    on at

    The only way that i could think of was to set "If" condition on first screen button "Login" but still not working...

    I tried to set 2 "If" conditions on this button as follows:

    If(!IsBlank(LookUp(UserTimeApp, Title=UserField.Text And Password=PassField.Text).Title), Navigate(MainScreen), UpdateContext({ShowForgetMessage:true}));
    If(LookUp('Time Records', varNewItem.ID = ID, 'Active Session' = true), Navigate(Parent); UpdateContext({ShowPopupSession: true}), Navigate(MainScreen));

     First line is checking in a SharePoint List for the user and password and if these are not correct it displays an error saying user or pass incorrect ... and if they are correct it goes to MainScreen.

    Then I used the second "If" to check in SharePoint List for ID and "Active session" to be "true" and if these 2 conditions are true it should popup a 'warning info' saying that there is already a session running

    CristianF_0-1644245497938.png

    but it doesn't work...

    What am i doing wrong ?

    Any help will be very usefull...

    Thank you !

  • RandyHayes Profile Picture
    76,297 Super User 2024 Season 1 on at

    @Anonymous 

    Is Parent the name of a screen??   Not sure what you are attempting there!

     

    As I see it, your formula should be the following:

    If(
     LookUp(UserTimeApp, Title=UserField.Text && Password=PassField.Text, true), 
     
     If(LookUp('Time Records', varNewItem.ID = ID && 'Active Session', true), 
     Navigate(Parent); 
     UpdateContext({ShowPopupSession: true}), 
     
     Navigate(MainScreen)
     ),
     
    
     UpdateContext({ShowForgetMessage:true})
    )
    
    
  • Community Power Platform Member Profile Picture
    on at

    @RandyHayes 

    'Parent' is not the name of a screen.

     Navigate(Parent); 
     UpdateContext({ShowPopupSession: true})

    This is a 'group' that forms a 'popup' message

    CristianF_0-1644264086624.pngCristianF_1-1644264114473.png

     

    The formula you provided did not work but I am 100% that it didn't because of my ...

    Navigate(Parent); UpdateContext({ShowPopupSession: true})

    I guess this is not the way it is supposed to work.

     

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 765 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 272

Last 30 days Overall leaderboard