Add a Synchronize Action to a Mobile Form
Mobile Framework
Add a Synchronize Action to a Mobile Form
The Data Synchronization action involves transferring data from the mobile device to the Web Central database. Data is typically sent to the Web Central server where it is then processed by one or more workflow rules.
A typical sync action involves the following steps:
- Transfer data from the mobile device to the Web Central database
- The mobile device initiates one or more workflow rules that act on the transferred data
- Transfer data from the Web Central database to the mobile device
The mobile framework performs the synchronization using the
Common.store.sync.SyncStore.syncStore()
function.
Steps required to add a synchronize action for an new table:
-
Create the Model class by extending the
Common.data.Model
class -
Create the Store class by extending the
Common.store.sync.SyncStore
class
Examples
The
Maintenance.controller.WorkRequestSync
file manages the sync functions for the Maintenance app. The Maintenance app transaction tables are synchronized using the
syncWorkRequest
function.
- storeIds - list of store ids to be synchronized
Note that the synchronization function
SyncManager.syncTransactionTables()
is called twice, the
executeWorkflowRules()
executes a server-side workflow rule to act on the data, followed by the second synchronization to transfer the data back to the mobile device.
File: ab-products/common/mobile/src/Maintenance/app/controller/WorkRequestSync.js
To create the new Model, extend
Common.data.Model
:
Ext.define('Maintenance.model.WorkRequest', {
extend : 'Common.data.Model',
config : {
fields : [
{ name : 'id', type : 'auto' },
{ name : 'mob_wr_id', type : 'IntegerClass' }, ...
File: ab-products/common/mobile/src/Maintenance/app/model/WorkRequest.js
To create the new Store, extend
Common.store.sync.SyncStore
and reference the new Model:
Ext.define('Maintenance.store.WorkRequests', {
extend : 'Common.store.sync.SyncStore',
requires : [ 'Maintenance.model.WorkRequest' ],
...
config : {
model : 'Maintenance.model.WorkRequest',
storeId : 'workRequestsStore',
File : ab-products/common/mobile/src/Maintenance/app/store/WorkRequests.js
To add a new transaction table to the synchronization, add the new
storeId
to the
transactionTableStoreIds
list of the
config
property:
Ext.define('Maintenance.controller.WorkRequestSync', { ... Common.service.Session.start() ... .then(function () { return SyncManager.syncTransactionTables(transactionTableStoreIds); }) .then(function() { Mask.setLoadingMessage(me.getUpdateMessage()); return me.executeWorkflowRules(); }) .then(function(result) { ... return SyncManager.syncTransactionTables(transactionTableStoreIds); }) ...
File: ab-products/common/mobile/src/Maintenance/app/controller/WorkRequestSync.js
The
executeWorkflowRules()
function is further detailed in the next topic
Calling a Server-Side Workflow Rule
.