Skip to content

VMXFoundry.OfflineObjects.startSync

The VMXFoundry.OfflineObjects.startSync API performs sync on all the object services published in the Volt MX Foundry application.

Note:

  • If sync is performed in an upload cache enabled scenario, cached requests that are timed out in the previous upload session are uploaded before the latest changes.
  • The client does not handle partial records and expects the server to send the entire record. Full record with all the columns are expected in both upload and download responses. If the backend does not return the full record, use post processor to copy the missing columns from the request as demonstrated here.

Volt MX Iris (JavaScript)

Note:

  • Supported for Windows from V8 SP4 Fix Pack 6 onwards.
  • Supported for Mobile Web and Desktop Web channels from V8 SP4 Fix Pack 12 onwards.

Signature

VMXFoundry.OfflineObjects.startSync(options, successCallback, failureCallback, progressCallback)

Input Parameters

ParameterTypeDescriptionRequired
optionsJSONThe user can provide options to customize sync behavior. For example, syncMode and objectServicesOptions. For information on supported options, refer to Sync Options.Yes
successCallbackFunctionThe function is invoked on successful sync with response as an argument. Based on the supplied sync options, the response object includes sync status code, sync stats and so on.Yes
failureCallbackFunctionThe function is invoked on an error with the cause of failure as an argument upon sync failure.Yes
progressCallbackFunctionThe function is invoked on different sync phases along with specific data such as the number of downloaded records and so on. Note: This parameter is only supported for Android, iOS, and Windows channels.No

Sync Options

Option Type Description Required
syncMode String Option to perform object services sync in sequence or parallel. The values could be{"parallel", "sequential"}
Note: Default sync mode is parallel, if not provided in options.
No
objectServicesOptions JSON The user can provide options to customize sync behavior. For example, Filters, downloadBatchSize and so on. For more details, refer Sync Options for supported options and Offline Objects Getting Started guide. No

Success Callback Response

Success Object Keys Type Description
successResponse JSON It contains object service name as keys and object service sync success response as values.

Failure Callback Error

Failure Object Keys Type Description
successResponse JSON It contains object service name as keys and object service sync success response as values.
failureResponse JSON It contains object service name as keys and object service sync failure response as values.

Return Type

void

Example

var options = {};
var organizationUploadRequestQueryParams = {
"LocationID": "32001",
"SiteID": "2"
};
var organizationOptions = {
"getSyncStats": "true",
"uploadBatchSize": "200",
"uploadRequestQueryParams": organizationUploadRequestQueryParams,
"syncType": "uploadOnly"
};
options.syncMode = "parallel";
options.objectServicesOptions = {
" Organization": organizationOptions
};

VMXFoundry.OfflineObjects.startSync(options, onSuccess, onFailure, onProgress);

function onSuccess(response) {
voltmx.print("Application Sync success: " + JSON.stringify(response.successResponse));
}

function onFailure(error) {
voltmx.print("Application Sync failed with error: " + JSON.stringify(error.failureResponse));
}

function onProgress(object) {
voltmx.print("Application Sync progress event received" + JSON.stringify(object));
}

Android (Java)

Signature

void <OfflineObjects>.startSync(final HashMap<String, Object> options, final VMXCallback syncCallback, final VMXProgressCallback voltmxSyncProgressCallback)

Parameters

ParameterTypeDescriptionRequired
optionsHashMap<String, Object>The user can provide options to customize sync behavior. For example, syncMode and objectServicesOptions. For supported options, refer Sync Options.Yes
syncCallbackVMXCallbackThe application implements onSuccess and onFailure methods of VMXCallback interface.Yes
voltmxSyncProgressCallbackVMXProgressCallbackApplication implements onProgress method of VMXProgressCallback interface if progress callback is supplied.Yes

Sync Options

Option Type Description Required
syncMode String Option to perform object services sync in sequence or parallel. The values could be{"parallel", "sequential"}
Note: Default sync mode is parallel, if not provided in options.
No
objectServicesOptions HashMap The user can provide options to customize sync behavior. For example, Filters, downloadBatchSize and so on. For more details, refer Sync Options for supported options and Offline Objects Getting Started guide. No

Success Callback Response

Success Object Keys Type Description
successResponse HashMap It contains object service name as keys and object service sync success response as values.

Failure Callback Error

Failure Object Keys Type Description
userInfo HashMap It contains HashMaps with keys successResponse and failureResponse. successResponse contains HashMap of object service name as keys and object service sync success response as values. failureResponse contains HashMap of object service name as keys and object service sync failure response as values.

Return Type

void

Example

try {
VoltMXClient sdk = new VoltMXClient();
IVoltMXApplicationSync appSync = sdk.getOfflineObjects();
HashMap < String, Object > objectServicesOptions = new HashMap < String, Object > ();
HashMap < String, Object > organizationOptions = new HashMap < String, Object > ();
HashMap < String, String > organizationUploadRequestQueryParams = new HashMap < String, String > ();
organizationOptions.put("uploadBatchSize", "100");
organizationOptions.put("getSyncStats", "true");
organizationOptions.put("syncType", "uploadOnly");
organizationUploadRequestQueryParams("LocationID", "32001");
organizationUploadRequestQueryParams("SiteID", "2");
organizationOptions.put("uploadRequestQueryParams", organizationUploadRequestQueryParams);
HashMap < String, Object > options = new HashMap < > ();
options.put("syncMode", "parallel");
objectServicesOptions.put("Organization", organizationOptions);
options.put("objectServicesOptions", objectServicesOptions);

    appSync.startSync(options, new VMXCallback() {
            @Override
            public void onSuccess(Object object) {
                HashMap < String, Object > result = (HashMap < String, Object > ) object;
                Log.d("ObjectServiceSync", "ObjectService sync successful." + result.get("successResponse"));
            }
            @Override
            public void onFailure(Object error) {
                OfflineObjectsException e = (OfflineObjectsException) error;
                Log.e("ObjectServiceSync", "ObjectService sync
        failed with error: " + e.getMessage());
            }
        },
        new VMXProgressCallback() {
            @Override
            public void onProgress(Object object) {
                Log.d("ObjectServiceSync", "ObjectService sync progress event received");
            }
        });

} catch (Exception e) {
Log.e("ObjectServiceSync", "ObjectService sync failed with error:" + e.getMessage());
}

iOS (Objective C)

Signature

(void) <OfflineObjects>startSync:(NSDictionary<NSString _, id> _)options
onSuccess:(VMXSuccessCompletionHandler)onSuccess
onFailure:(VMXFailureCompletionHandler)onFailure
onProgress:(VMXProgressCompletionHandler)onProgress;

Parameters

Parameter Type Description Required
options NSDictionary* The user can provide options to customize sync behavior. For example, syncMode and objectServicesOptions. Refer Sync Options for supported options. Yes
onSuccess VMXSuccessCompletionHandler The function is invoked on successful sync. Yes
onFailure VMXFailureCompletionHandler The function is invoked on sync failure. Yes
onProgress VMXProgressCompletionHandler The function is invoked on sync progress events. Yes

Sync Options

Option Type Description Required
syncMode String Option to perform object services sync in sequence or parallel. The values could be{"parallel", "sequential"}
Note: Default sync mode is parallel, if not provided in options.
No
objectServicesOptions NSDictionary The user can provide options to customize sync behavior. For example, Filters, downloadBatchSize, and so on. For more details, refer Sync Options for supported options and Offline Objects Getting Started guide. Yes

Sync Callback Response

Success Object Keys Type Description
successResponse NSDictionary* It contains object service names as keys and object service sync success response as values.

Failure Callback Error

Failure Object Keys Type Description
userInfo NSDictionary * It contains NSDictionaries with keys successResponse and failureResponse keys. successResponse contains NSDictionary of object service name as keys and object service sync success response as values. failureResponse contains NSDictionary of object service name as keys and object service sync failure response as values.

Return Type

void

Example

NSError _ error;
VMXClient _ sdk = [VMXClient sharedClient];
OfflineObjects \* applicationSync = [sdk getOfflineObjects];

VMXSuccessCompletionHandler onSuccess = ^ void(id object) {
//Operation to be performed on successful sync.
};
VMXFailureCompletionHandler onFailure = ^ void(id object) {
//Operation to be performed on sync failure.
};
VMXProgressCompletionHandler onProgress = ^ void(id object) {
//Operation to be performed on sync progress.
};
NSDictionary _ uploadRequestQueryParams = @ {@
"LocationID": @“32001”,
@"SiteID": @"2"
};
NSDictionary _ filters = @ {@
"Employee": @"EmployeeID eq 2",
@"Department": @"Name eq ‘Human Resource’"
};
NSDictionary _ syncOptions = @ {@
"uploadRequestQueryParams": uploadRequestQueryParams,
@"filter": filters,
@"downloadBatchSize": @"100",
@"uploadBatchSize": @"200",
@"getSyncStats": @"true",
@"syncType": @"fullSync"
};
NSDictionary _ objectServicesOptions = @ {@
"Organization": syncOptions
}
[applicationSync startsync: @{@
"syncMode": "parallel",
@"objectServicesOptions": objectServicesOptions
}
onSuccess: onSuccess
onFailure: onFailure
onProgress: onProgress
];