Skip to main content

Developing an Application

 

Applies only to Mobile Apps
OutSystems

Implementing Offline Synchronization

OutSystems provides a framework for syncing data between your mobile application and server. The framework consists of a set of actions and blocks available in the Silk UI mobile app templates and enables you to create the business logic, trigger the sync and react to sync outcomes and changes in network status. The sync implementation using this framework implies that the server data model has been adapted into a lightweight local entity data model.

The actions within the server OfflineDataSync folder get the data from the server, and then pass it to the client OfflineDataSync logic. The business logic for updating individual entities (lists, loops, logical branching, conflict detection, additional tables for meta data) is implemented in actions that are part of the client OfflineDataSync folder. This logic depends on the use case, but the basic patterns can be generated if you right-click a local entity.

The event listeners in the Source Block of individual screens can be used to create actions that control how the UI elements respond to the sync outcomes or changes in network statuses.

The sync can be automatic and manual. If the sync is manual, it should be started by calling the action TriggerOfflineDataSync.

Reference

We are listing the elements belonging to the framework for syncing data between the server and the application.

Logic tab -> Client Actions -> OfflineDataSync folder

OfflineDataSync folder in Client Actions should contain all actions that run on the mobile device to update local entities and exchange data with the corresponding actions in the server side of the logic.

OfflineDataSyncConfiguration

Contains multiple assignments to configure automatic start and retry of the sync:

  • SyncOnOnline - set to True to trigger the sync when the device comes online
  • SyncOnLogin - set to True to trigger the sync after login
  • SyncOnResume - set to True to trigger the sync once the application resumes from the background
  • RetryOnError - set to True to attempt a new sync in case of an error
  • RetryIntervalInSeconds - set the interval for the sync retry in seconds

TriggerOfflineDataSync

Use TriggerOfflineDataSync to start the sync. TriggerOfflineDataSync is optimized for asynchronous sync that runs in the background and for triggering the sync events. Do not call OfflineDataSync to start the sync unless you want to block the flow execution and you do not need to trigger the sync events.

SyncUnit
String input parameter that can be passed from business logic to the sync actions. Useful for deciding which entity to sync.
DiscardPendingSyncUnits
If set to True clears the sync queue. Useful when you want to abort the pending syncs and start a new one immediately.

OfflineDataSync

OfflineDataSync is the default action that can be used for creating logic executed on the client.

SyncUnit
String input parameter that can be passed from business logic to the sync actions. Useful for deciding which entity to sync.

Logic tab -> Server Actions -> OfflineDataSync folder

OfflineDataSync folder in Server Actions should contain all actions that run on the server to update server entities and exchange data with the corresponding actions in the client side of the logic.

OfflineDataSync

OfflineDataSync is the default action that can be used for creating logic executed on the server.

SyncUnit
String input parameter that can be passed from business logic to the sync actions. Useful for deciding which entity to sync.

Logic tab -> Client Actions -> MobilePatterns

Mobile apps come with two actions to detect network status and type. These are also accessible as functions in expressions.

GetNetworkStatus

Returns a Boolean value. True for online, False for offline.

GetNetworkType

Returns a text value. Describes the type of network, for example, wifi, 4g, undefined (if in the browser preview).

Interface tab -> UI Flows -> Common -> Layout and LayoutBlank

Handle the following events to have the application react to sync start, end or error.

To create actions as event listeners of these events, open the widget tree of a screen, select the Layout or LayoutBlank block instance in the screen and fill the Handler properties that correspond to the events.

OnSyncComplete

Event triggered once the sync is successfully executed.

SyncUnit
String input parameter that can be passed from business logic to the sync actions. Useful for deciding which entity to sync.

OnSyncError

Event triggered if the sync fails.

SyncUnit
String input parameter that can be passed from business logic to the sync actions. Useful for deciding which entity to sync.
ErrorMessage
A string identifying the error.

OnSyncStart

Event triggered when the sync starts.

SyncUnit
String input parameter that can be passed from business logic to the sync actions. Useful for deciding which entity to sync.

Interface tab -> UI Flows -> MobilePatterns -> Private

Contains a block that you can use to listen if the application is online or offline.

NetworkStatusChanged block

Drag the block to a Screen and then create a new action handler for NetworkStatusChanged event. In the flow of the event handler place the logic that reacts to IsOnline input.

  • Was this article helpful?