Offline Data Sync DB & Local Help for Issues

Offline Data Sync DB & Local Help for Issues

  

Hi,

I have created a DB on eSpace & imported in Mobile application, Mobile app if Implemented with Read-Write Last Win Pattern as per Document.

Note:

- I have used Sync Action from Logic for Delete & Create/Update

- I have called SyncLocalTableAction of Client in OfflineDataSync as per document.

Below are my some queries to be cleared:

1- There is one table in my DB server, but I want to only get records based on user & current date only, Should I add filter on Local Entity / Entity in DB Table...?

2- Once I delete the record, it should also be deleted on Server DB, I check it delete from local but shows me on server DB?

3- If I edit & update, it should also be reflected on server DB?

4- what is the best method approach & offlineDataSyncConfig to be use for Offline-Online Data Sync?

5- Should I add action on onReady State of Home  screen to fetch Data, but before that adding a check of GetNetworkStatus & calling the TriggerOfflineDataSync?


I know this might be 5 diffrent post , but they all are relalted to same, thus I post here in same thread.

Thanks,

Assif



Solution

Hi Assif,

before trying to answer your questions, let me say the online training has lessons on Local Storage, Offline and Data Syncronization that you should probably review and make sure you can implement their respective exercises.

  1. If you only need data specific to that user locally on your mobile device, then yes, only fetch from the server data (Database entities) already filtered by user. Current Date may be trickier, as server-date and device date will not be the same, so filtering that on the server-side may give results that you don't really want (the date may be different because of timezones). You may need to fetch 3-days worth of data (to be on the safe side) and then filter on the client-side (Local Storage entities) aggregates... or determine local timezone and pass that to the server so you can filter it properly on the server-side.
  2. If you follow the data sync pattern (check the exercise instructions and the sync patterns documentation), you will realize records aren't actually deleted on the device, they are just marked as deleted. This allows the sync logic to send those records to the server, so it knows which should be deleted. Once it syncs back to the device, then they will be permanently deleted also on the device.
  3. Yes, again, the pattern already deals with this, by marking those records as updated.
  4. Deciding if you want to sync data when a user logs in, resumes using the app or when the app became online again really depends on your requirements... here I'd say you probably want to sync when the user logs in (you want to synchronise a different set of data) and when the app becomes online again (so you can push your changes to the server as soon as possible), but every case is a case.
  5. I don't understand what you are trying to achieve with this...
Solution

Hi Jorge,

Thanks for the awesome reply :)

Well :

1- ok

2- Then it was showing me the records still on DB server table, even after delete & sync 

3-ok

4-So If i set the required flags in offlineDataSyncConfig , than there will no need to manually call Sync ?

5- It was for calling Maunally the Sync Trigger


Thanks


assif_tiger,

In order to understand your issue with 2) I suggest you check your logic: if the records aren't being deleted on the Database entity, you probably are doing something wrong. Use the debugger to see the list of records to be deleted that is sent to the Server, and follow the execution flow to make sure they are being deleted properly and that the transaction commits successfully.

Regarding 4), automatic syncing can only happen on those three moments: when a user logs in, when the application becomes online again or when the app was in the background and is resumed (becomes the foreground app again, the one the user interacts with). Depending on your application logic, these might be enough, or you may need to trigger synchronisation explicitly:

  • If, when the device is online, your application performs the operations both on the server and on the device (this would be my approach, and if I'm not mistaken, what's described on the exercise I mentioned above), then you are correct.
  • If, on the other hand, your device always works on the Local Storage entities only, then you will need to trigger synchronisation for the changes to be reflected on the server.

Finally 5)... there are many places and patterns you can use to allow the user to trigger syncing... simple ones would be to have a button or link somewhere to explicitly trigger the sync (asynchronously) or the pull to refresh to force the data to be synced (in this case it might make sense for it to be synchronous, by directly calling the OfflineDataSync client action, instead of using TriggerOfflineDataSync).

Hope this clarifies things.

Hey Jorge,

That's Something Awesome Explanation. Thanks for your time,

Cheers,

Assif

Jorge Martins wrote:

Hi Assif,

before trying to answer your questions, let me say the online training has lessons on Local Storage, Offline and Data Syncronization that you should probably review and make sure you can implement their respective exercises.

  1. If you only need data specific to that user locally on your mobile device, then yes, only fetch from the server data (Database entities) already filtered by user. Current Date may be trickier, as server-date and device date will not be the same, so filtering that on the server-side may give results that you don't really want (the date may be different because of timezones). You may need to fetch 3-days worth of data (to be on the safe side) and then filter on the client-side (Local Storage entities) aggregates... or determine local timezone and pass that to the server so you can filter it properly on the server-side.
  2. If you follow the data sync pattern (check the exercise instructions and the sync patterns documentation), you will realize records aren't actually deleted on the device, they are just marked as deleted. This allows the sync logic to send those records to the server, so it knows which should be deleted. Once it syncs back to the device, then they will be permanently deleted also on the device.
  3. Yes, again, the pattern already deals with this, by marking those records as updated.
  4. Deciding if you want to sync data when a user logs in, resumes using the app or when the app became online again really depends on your requirements... here I'd say you probably want to sync when the user logs in (you want to synchronise a different set of data) and when the app becomes online again (so you can push your changes to the server as soon as possible), but every case is a case.
  5. I don't understand what you are trying to achieve with this...


Jorge Martins, Just to clear things with point1-1:


1- If I want to get User Specific Data from Server then where should I add a filter with respect to UserID.

  A) Filter on Aggregate on Screen like : Table.UserID=GetUserID()

  B) DataBase Entity [ But how]


Thanks,

Assif

Hi Assif,

If you want to filter server side data to sync, you'll want to do it in an (Database) Aggregate or SQL

Jorge Martins wrote:

Hi Assif,

If you want to filter server side data to sync, you'll want to do it in an (Database) Aggregate or SQL

You mean I should use direct DB Entity Aggregate on Screen instead of Local, Coz I created Entities in Local i.e copied from my DB section which I used in entire project.

Also facing an issue with Update:
 Ï have used the UpdateTablelForsync Action of Login Tab in Screen, The issue is when I update any existing record from app, it added as an new entry in local table. whereas I pass same recordID to it.


Hi assif_tiger,

You mean I should use direct DB Entity Aggregate on Screen instead of Local, Coz I created Entities in Local i.e copied from my DB section which I used in entire project.

Not on your Screens, we are talking about synchronisation... I meant on your ServerDataSync Server Action.

Also facing an issue with Update:
 Ï have used the UpdateTablelForsync Action of Login Tab in Screen, The issue is when I update any existing record from app, it added as an new entry in local table. whereas I pass same recordID to it.

I have no idea what "UpdateTablelForsync Action of Login Tab in Screen" is... 

A word of caution though: the Id assigned when you first create a record on the Database can be different from the Id that was assigned when you created the record on LocalStorage, this is why the sync patterns typically delete all data from the LocalStorage before adding back all the records it received from the server.