Data synchronization JavaScript API

When you design an application that users can access with an offline-enabled mobile app on a mobile device, you can configure data synchronization frequency, data synchronization throttling, and the behavior of the synchronization indicator, by calling several JavaScript methods.

You might want to initiate the synchronization, for example, to pass case processing results to the server. The following JavaScript API triggers immediate data synchronization.
window.datasyncStart()
Initiates data synchronization when the user interacts with the control that you configure to invoke the Run script action. When the datasyncStart method is called, the synchronization indicator immediately displays the Syncing/Synced message.
pega.offline.DataSync.start
Initiates data synchronization when called from the custom JavaScript code that defines the logic of your application. When the start method is called, the synchronization indicator does not present the Syncing/Synced label, unless there has been a noticeable delay.
You might want to decrease the default synchronization frequency, for example, to limit battery consumption and network usage. Alternatively, you might want to increase the frequency, for example, to ensure that users always have the most recent data, despite an intermittent network connection. The following JavaScript API delays synchronization for a specified time.
pega.offline.DataSync.setIntervalBetweenSynchronizationsWhenServerAccessible
Sets the interval (in milliseconds) between subsequent synchronization sessions when the server is available. The default value is 300000 ms (5 minutes). The value must be greater than 0.
pega.offline.DataSync.setIntervalBetweenSynchronizationsWhenServerInaccessible
Sets the interval (in milliseconds) between subsequent synchronization sessions when the server is not available. The default value is 60000 ms (1 minute). The value must be greater than 0.
You might want to introduce synchronization throttling, for example, to decrease server load or to limit battery consumption and network usage. The following JavaScript API controls throttling and delays synchronization until a certain number of actions are in the action queue.
pega.offline.DataSync.setQueueMaxSize
Sets the number of actions in the action queue that must be reached before synchronization is triggered. The default value is 1, which means that the app sends actions immediately to the server after they are added to the action queue.
pega.offline.DataSync.setQueueFlushInterval
Sets the amount of time (in milliseconds) that must pass from the moment an action is queued in the client store before synchronization is triggered. The default value is 0, which means synchronization happens immediately.
pega.offline.DataSync.enableFlushOnLastStep
Enables or disables synchronization triggering after the user processes the last step in an assignment. The default value is false.
pega.offline.DataSync.isFlushOnLastStepEnabled
Specifies whether synchronization triggering is enabled after the user processes the last step in an assignment.
When a network connection is not available for a long period of time and a large number of user actions accumulate for synchronization, you might want to decrease server load to ensure that the oldest user actions get synchronized. The following JavaScript API splits a synchronization session into parts.
pega.offline.DataSync.setMaxNumberOfActionsPerRequest
Sets the maximum number of actions that can be sent with a single request. The default value is 60, which means that the app sends up to 60 actions in each synchronization request. When you set the value to -1, you remove the limit, which means that a synchronization request can include an infinite number of actions.
For usability or customization reasons, you might want to modify how the synchronization indicator is displayed. The following JavaScript API controls the appearance of the synchronization status indicator.
Note: Use the following JavaScript API controls for UI-Kit 14 and earlier versions. For UI-Kit 15 and Pega Cosmos design system , modify how you display the synchronization indicator by configuring corresponding dynamic system settings. For more information, see Configuring time-outs for synchronization indicators.
pega.offline.Indicator.setDeferDurationTime
Sets the time (in milliseconds) that must pass from the start of the synchronization session before the Syncing/Synced label appears on the screen. By default, it is set to 4000 ms (4 seconds). The value must be greater than 0.
pega.offline.Indicator.setHideSyncedAfterTime
Sets the time (in milliseconds) that must pass from the end of the synchronization session before the Synced label disappears from the screen. The default value is 5000 ms (5 seconds). The value must be greater than 0.