I am building an app to allow field officers to collect and UPDATE data about remote sites where online connectivity is patchy at best. There are some very simple examples to allow new data to be added offline and update later when online but it gets more complicated when a lot of the time you are checking and updating existing data. About 300 sites are visited repeatedly. The field officer needs to check whether data on a SharePoint list is up to date and if neccessary correct it or add a record for a new site.
Each site is described by about 25+ columns in a SharePoint list called TableSites. Column colSiteCode is a unique identifier Several field officers may be working on different sites at the same time but two field officers would never be independently visiting the same site so wouldn't be updating the same the record at the same time so there are no worries about conflicts.
I have seen versions of what seems to be the same solution that allow you to copy data down while online, work on the offline copy and use Patch() to copy the data back when you are online. The examples I have seen have only two or three columns. The problem with Patch(), at least in the examples I have seen, is I would need to specfy the names and values for all 25+ columns. This feels clumsy, makes it too easy to make a mistake and too difficult to change the columns in the future as any column I add or rename in SharePoint will also have to be renamed in the app. Is there a different function or a way to use Patch() that adds all the values of this row of the collection to the list or update all the values of the list to match the values in the collection without specifying all the column names? To make things easy LocalSites is made from TableSites and OfflineSites is made from LocalSites everytime there is a connection so the column names, order, type, etc should all be the same.
The solutions I have seen also assume you will go online and upload the data before you close down the app - that isn't always possible. I think it is safer to assume when the app opens it needs to check for any updates to the server before overwritting the local dataset from the server. That is easy enough for me to do.
My App started life as a standard three screen app built automatically based on the SharePoint list but with these changes.
When app opens it copies TableSites to collection LocalSites and saves it to "OfflineSites". Items for the browse screen gallery were changed to selected data from LocalSites instead of TableSites. Various other corrections were then neccessary to point at LocalSites instead of TableSites but basically it all works.
When a record is changed colStatus is changed from, "Online", (i.e. the record is already correct online) to, "Updated", if any column is changed or, "Added" for a new record When a record is changed or added or the refresh button is clicked or the app is opened (and possibly on a timer too) I open a screen called UpdateScreen
UpdateScreen.OnVisible checks if the app is connected using If(And(Connection.Connected,CountIf(LocalSites,Not(colStatus = "Online")) > 0), //then do some stuff (Depending how quick this process runs I might add a pretty countdown timer on UpdateScreen. If there is no connection there could also be a reminder to go online soon and upload recent data)
HELP PLEASE!
The stuff I want to do but am stuck are:
For rows in LocalSites where colStatus = "Add", add a copy of the whole row to TableSites
For rows in LocalSites where colStatus = "Update", find the correct row in TableSites and update all the columns to match the values in LocalSites Update colStatus to, "Online", as each row is updated so that row isn't used to trigger an update again.
HELP PLEASE!
I will then Clear collect all the data back from TableSites to LocalSites and save a new copy to, "OfflineSites", to make sure the Field Officer has the latest version of data for the site they will visit next
Thank you very much for your help. Guy