cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper IV
Helper IV

Offline powerapps

Hi I have a question. I need to develop an apps that can be used while offline.

When internet isnt available, the data is stored in collection, but is it possible to edit the data stored in the collection before it sync back to cds when internet is available? 

6 REPLIES 6
Highlighted
Super User
Super User

Re: Offline powerapps

@NurNina 

Yes, it is possible to edit the data stored in a collection before it syncs back to CDS.  Here's a pseudocode example

 

When the internet is not available you can save data to the local storage

If(Connection.Connected, 
some code to update your datasource;
SaveData(your_collection_name, your_local_storage_name))

 

When the internet is not available you could load data from local storage.

 

If(Connection.Connected, 
ClearCollect(your_collection_name, your_datasource_name);
LoadData(your_collection_name, your_local_storage_name, true))

 

 

---
Please click "Accept as Solution" if my response helped to solve your issue so that others may find it more quickly. If your thought the post was helpful please give it a "Thumbs Up."

Highlighted
Impactful Individual
Impactful Individual

Re: Offline powerapps

I handle it by having a "Changes" collection that I have on the device, and savedata to a file after each change. This way if the app crashes or restarts etc. it can load those changes back in at the beginning and read those into the app.

But basically you store the changes, then either by timer job trying to check for connection, or you have the UI guide them to upload when connected (hide button when not), then use a ForAll patch through your changes collection to upload those changes, then clean up.
Highlighted
Helper IV
Helper IV

Re: Offline powerapps

So lets say if I just created an order while offline, and then I want to edit the details first before sync back to cds.is it possible?

Highlighted
Super User
Super User

Re: Offline powerapps

@NurNina 

I can't say I know much on CDS so let's see what @cwebb365 has to say on that one...

 

While doing some of my own research today I came across a fantasic article that discussed offline mode at length.  I found it very useful, you might too...  https://jobs.collab365.community/powerapps-offline-disconnected-mode/

Highlighted
Impactful Individual
Impactful Individual

Re: Offline powerapps

Editing is a bit harder. But no reason why you couldn't have your local collection and changes collection both get a record when you add a new one. If you edit, then edit from the local collection, but save that edit to the local changes collection, and if one exists in there already, then update with that change.
Highlighted
Super User
Super User

Re: Offline powerapps

I haven't done this with CDS, but with SharePoint and SQL my approach was:

When making a changes to the records in a collection, save them to the same local collection, but usethe modified date as a flag (with Sharepoint use the built in modified date field, in SQL create a modified date field that defaults to the current date).

Anything without a modified date is a new record.

When deleting a record set the modified date to an arbitaty date that is in the past (e.g. 1 Jan 2000)

When modifiying an existing record, set the modified date to a different arbitrary date in the past (e.g. 1 Jan 2001)

 

You can then build a sync routine that does the following:

Filter on Blank modified date and insert those records

Filter on modified date = 1 Jan 2001 and perform a ForAll and Patch the changes (if using SQL set the modified date to Now())

Filter on modified date = 1 Jan 2000 and delete those records

 

Finally, repopulate (clearcollect) your local collections from the data in your datasource

 

Ensure that after every change, deletion, insert, you do a SaveDate. Repopulate your collections with a LoadData when the App opens. Whenever using a local collection in the App remember to filter out records where modified date indicates they are deleted.

 

Note that this assumes that any change made by your App should 'win' in any conflict (e.g. a conflicting change is made in the datasource before the App next syncs its changes). You could build some logic around this but it would be very complex.

Helpful resources

Announcements
secondImage

Demo-Extravaganza 2020

Check out these cool Power Apps & vote on your favorite!

secondImage

Community Highlights

Check out whats happening in Power Apps

secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (14,709)