Official Content

The Synchronization API is a very useful tool that makes synchronization between the Device and the Server extremely easy. You do not have to worry about how to apply changes on the server, or how to receive data changes from the server and apply them on the device.
The Synchronization API has two methods: Receive and Send, that makes that hard work automatically.

It is very important to note that the Synchronization API can be called at any time, even if the developer has set any value for the Data Receive Criteria property or Send Changes property, both methods Receive and Send are still going to work.

This document explains how to create a simple offline application calling the synchronization programs manually, using the Synchronization API to synchronize the device with the server. 

Note: If you are interested on calling the synchronization programs automatically, then you should check out the Automatic Offline Data Synchronization document.

How it works

Take the "Simple Version Manual" version of the Sales sample as an example. In this application's version, the application needs to be synchronized whenever the user wants to.

The first step to do that is to configure the Offline Database Object properties. As in this sample application it is necessary to manage the synchronization manually, it is needed to set the Data Receive Criteria property  and the Send Changes property to "Manual" as shown in the following image:

offlinedatabase v18

The second step is to create a new Panel. In this example it is called “SynchPanel”, and adds 2 buttons in the layout like shown in the image below:

SynchPanel for Synchronization API article - v18

Finally, each button is going to have an event where the Synchronization API is called:

Event 'Receive'
    Synchronization.Receive()
Endevent

Event 'Send'
    Synchronization.Send()
Endevent

By doing just that, it is possible to synchronize data whenever the user wants to. When tapping the "Receive" button, the data from the server is going to be synchronized into the device, and when tapping the Send button, all local changes are submitted to the server in order to apply changes.

Limitations

The Synchronization.Send method sends data to the server in a single request, that may be a problem if connectivity is very unstable and the amount of data to send is big. In that case, consider executing it when a stable connection is available or Coding your Data Synchronization programs.

See Also

Sales sample
Synchronization API
Synchronization.Receive method
Synchronization.Send method
Synchronization.ResetOfflineDatabase method
Coding your Data Synchronization programs

Last update: April 2024 | © GeneXus. All rights reserved. GeneXus Powered by Globant