cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
blue_lotus
Level: Powered On

saving offline records

Hello,

I am trying to save records while working offline, so that they get uploaded at the end of the day to my Sharepoint list when back online.

In my edit form, I create a collection with the info entered, save it to the phone's cache, and load the data which I display in a gallery.

Collect(offline_record,{date: DataCardValue22.SelectedDate,centre: Dropdown3.Selected.Value});
SaveData(offline_record,"offline_record_local_storage");
LoadData(offline_record,"offline_record_local_storage")

I created a gallery where I display the collection by setting the items property to offline_record, and it works. 

However, when I enter a new offline record, it replaces the previous one, instead of adding it up.
So my gallery always displays the last offline record entered, instead of the whole list of offline records.

If anyone has some advice that would be great.

Thanks a lot

1 ACCEPTED SOLUTION

Accepted Solutions
cwebb365
Level 10

Re: saving offline records

They are only disposed of if the app is closed. In that case, using the "OnStart" and using LoadData() to populate those collections will give you the data for offline. You just need to make sure as you use the app, that you update the offline files with savedata() on any changes after you update the collection. This way next time you load the app, the collections get populated with local data if offline.

View solution in original post

12 REPLIES 12
cwebb365
Level 10

Re: saving offline records

I wouldn't reload the data from cache in one step, it's probably not finishing the write to save before loading so It's loading the first one. Use Load on app start but not during the save. See if this helps at all.
blue_lotus
Level: Powered On

Re: saving offline records

Thank you for your help.

 

I broke the instruction in 2 steps: I do the Collect and the SaveData in one button.

 

And then I come out out of the app and on open I lood the data from the cache.

 

However I still get the same error.

 

It seems like when I save a new record it overwrites the previous in the cache....I don't know where I got it wrong

 

 

cwebb365
Level 10

Re: saving offline records

Anyway to post your code? Sure you don't have any odd characters on the files? I pulled my hair out once and found out the files are case sensitive and I had one letter caps on save vs my load one.
blue_lotus
Level: Powered On

Re: saving offline records

Thanks,
That's the code in the 1st button:

 

If(Connection.Connected,

If(Or(IsBlank(DataCardValue23),IsBlank(DataCardValue24),Value(Text(DataCardValue23))>30,Value(Text(DataCardValue23))<1,Value(Text(DataCardValue24))<70,Value(Text(DataCardValue24))>160),
UpdateContext({popup:true}),
SubmitForm(Form1);
Navigate(screen_welcome,ScreenTransition.None)),

Collect(offline_record,{date: DataCardValue22.SelectedDate,centre: Dropdown3.Selected.Value,bag: DataCardValue23.Text,sample1: DataCardValue24.Text,sample2: DataCardValue25.Text,sie: ListBox1.SelectedItems.Value,route: DataCardValue2.Text});


SaveData(offline_record,"offline_record_local_storage"))

And then, on open of the app:

LoadData(offline_record,"offline_record_local_storage")

 

Highlighted
seadude
Level 10

Re: saving offline records

Hi @blue_lotus. I see your code here. You can disregard my request in your other post. Here are some ideas that may help debug your issue:

  1. Ensure all your comparisons are correct.
    1. Put some debugging labels in your app that show the status of your comparisons.
    2. Example: Create a label with Text Property set to IsBlank(DataCardValue23). Make sure its accurate. Repeat this for all your comparisons.
  2. I've found quite few times that things are not always cut and dry with IsBlank. Depending on how you setup your options or the type of control, you may need to use = " " or IsEmpty. 
  3. Also < and > comparisons can get weird when you are converting things to Text then Value(), etc.
  4. Another idea is to put debug Gallery on the screen with its Items set to the LoadData() Collection. This will tell you what the data is on your mobile phone. It can be tricky to debug Load/SaveData() without this.

Good luck!

 

blue_lotus
Level: Powered On

Re: saving offline records

I followed your advice but it's still not working.

it just seems that I constantly overwrites the collection, instead of adding a new reocrd to the collection.

How can I get support on that? Im hitting a wall here.

 

Thanks

seadude
Level 10

Re: saving offline records

Hi @blue_lotus. So, all of your comparisons are correct? What does the Gallery show before and after you SaveData()? What does it show after you LoadData()?

blue_lotus
Level: Powered On

Re: saving offline records

Hi Seadude,

 

So i enter my record.

After i save, the records shows in the gallery which display the collection.

it is in the cache and then I load it to the collection. 

It appears on the unsaved_screens I have

 

Then I go out of the app. 
Still offline, I want to enter a 2nd record.

I save it, and it shows in the collection
I load it, and then, on the unsaved_screen, I can see that this 2nd record has overwritten the first one.

THat's my problem. At the end of the day working offline, I would like to have all my records saved on the phone, when I get to a place with wifi, i can upload all those records to my Sharpeoint list.

I hope it's clear, let me know if you need any other info,

 

Thanks a lot for your help

cwebb365
Level 10

Re: saving offline records

In my App, I use a separate collection that holds "changes" for uploading. Then have an upload screen that sends these to my data source. When I create any new records, I patch to my app collection and then to the changes collection and savedata() on both. Then when Online I use a forall using the addition collection to patch the changes to the online datasource. I only use Loaddata() to start the app up. This way no matter what, my changes collection won't get overwrote or be used in any way, and I can loop through just the additions into the data source. But luckily for me I only have additions, no edits / deletes, this complicates things a bit more :).

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (5,261)