<OfflineObjects>.startSync
The <OfflineObjects>.startSync API performs sync on all object services published in the Kony Fabric app.
Kony Visualizer (JavaScript)
Signature
KNYMobileFabric.OfflineObjects.startSync(options, successCallback, failureCallback, progressCallback)
Parameters
Parameter |
Type |
Description |
Required |
options |
JSON |
The user can provide options to customize sync behavior. For example, syncMode and objectServicesOptions.
Refer sync options for supported options. |
Yes |
successCallback |
Function |
The function is invoked on successful sync with response as an argument. Response object includes sync status code, sync stats etc based on the supplied sync options. |
Yes |
failureCallback |
Function |
The function is invoked on an error with the cause of failure as an argument upon Sync failure. |
Yes |
progressCallback |
Function |
The function is invoked on different sync phases along with phase specific data such as the number of records downloaded etc. Note: Not applicable for Windows, Mobile Web and Desktop Web channels. If app developer passes this parameter in the options, it will be ignored.
|
No |
Sync options
Options |
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 etc, Refer Sync Options for supported options. Refer Offline Objects Getting Started guide for more details. |
No |
Success callback response
Success object keys |
Type |
Description |
applicationSyncSuccessResponse |
JSON |
It contains object service name as keys and object service sync success response as values. |
Failure callback error
Failure object keys |
Type |
Description |
applicationSyncSuccessResponse |
JSON |
It contains object service name as keys and object service sync success response as values. |
applicationSyncFailureResponse |
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};
KNYMobileFabric.OfflineObjects.startSync(options, onSuccess, onFailure, onProgress);
function onSuccess(response){
kony.print("Application Sync success: " + JSON.stringify(response. applicationSyncSuccessResponse));
}
function onFailure(error){
kony.print("Application Sync failed with error: " + JSON.stringify(error. applicationSyncFailureResponse));
}
function onProgress(object){
kony.print("Application Sync progress event received" + JSON.stringify(object));
}
Android (Java)
Signature
void <OfflineObjects>.startSync(final HashMap<String, Object> options, final KNYCallback syncCallback, final KNYProgressCallback konySyncProgressCallback)
Parameters
Parameter |
Type |
Description |
Required |
options |
HashMap<String, Object> |
The user can provide two keys. One is “syncMode” and other is “objectServiceOptions”. Refer sync options for supported options. |
Yes |
syncCallback |
KNYCallback |
Application implements onSuccess and onFailure methods of KNYCallback interface. |
Yes |
konySyncProgressCallback |
KNYProgressCallback |
Application implements onProgress method of KNYProgressCallback interface if progress callback is supplied. |
No |
options
Options |
Type |
Descriptions |
Required |
syncMode |
String |
The option “syncMode” is used to indicate the Application Sync flow(“Parallel” or “Sequential”) .Default sync mode is parallel if “syncMode” option is not provided. |
No |
objectServiceOptions |
Map<String, Object> |
The user can provide options to customize sync behavior. For example, Filters, downloadBatchSize etc, Refer Sync Options for supported options. Refer Offline Objects Getting Started guide for more details.
|
No |
Success callback response
Success object keys |
Type |
Description |
applicationSyncSuccessResponse |
HashMap<String, Object> |
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<String, Object> |
It contains HashMaps with keys applicationSyncSuccessResponse and applicationSyncFailureResponse keys
|
Return Type
void
Example
try{
KonyClient sdk= new KonyClient();
OfflineObjects 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);
objectServicesOptions.put(“syncMode”, “parallel”);
objectServicesOptions.put(“Organization”, organizationOptions);
appSync.startSync(organizationOptions,
new KNYCallback() {
@Override
public void onSuccess(Object object) {
HashMap<String, Object> result = (HashMap<String, Object>) object;
Log.d(“ObjectServiceSync”, “ObjectService sync successful.”
+ result.get(“applicationSyncSuccessResponse”));
}
@Override
public void onFailure(Object error)
{
OfflineObjectsException e=(OfflineObjectsException)error;
Log.d("ObjectServiceSync", "ObjectService sync
failed with error: " + e.getMessage());
}
},
new KNYProgressCallback() {
@Override
public void onProgress(Object object) {
Log.d("ObjectServiceSync", "ObjectService sync progress event received");
}
});
} catch (Exception e) {
Log.d("ObjectServiceSync", "ObjectService sync failed with error:"
+ e.getMessage());
}
iOS (Objective C)
Signature
(void) <OfflineObjects>startSync:(NSDictionary<NSString *, id> *)options
onSuccess:(KNYSuccessCompletionHandler)onSuccess
onFailure:(KNYFailureCompletionHandler)onFailure
onProgress:(KNYProgressCompletionHandler)onProgress;
Parameters
Parameter |
Type |
Description |
Required |
options |
NSDictionary<NSString *, id> * |
The user can provide two keys. One is “syncMode” and other is “objectServiceOptions”.
|
Yes |
onSuccess |
KNYSuccessCompletionHandler |
The method called after a successful sync. |
Yes |
onFailure |
KNYFailureCompletionHandler |
The method called on sync failure. |
Yes |
onProgress |
KNYProgress CompletionHandler |
The method called on sync progress events. |
No |
syncOptions
Options |
Type |
Descriptions |
Required |
syncMode |
String |
The option “syncMode” is used to indicate the Application Sync flow(“Parallel” or “Sequential”) .Default sync mode is parallel if “syncMode” option is not provided. |
No |
objectServiceOptions |
NSDictionary<NSString*, id> |
The user can provide options to customize sync behavior. For example, Filters, downloadBatchSize etc, Refer Sync Options for supported options. Refer Offline Objects Getting Started guide for more details.
|
Yes |
Success callback response
Success object keys |
Type |
Description |
applicationSyncSuccessResponse |
HashMap<String, Object> |
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<String, Object> |
It contains HashMaps with keys applicationSyncSuccessResponse and applicationSyncFailureResponse keys
|
Return Type
void
Example
NSError *error;
KNYClient *sdk= [KNYClient sharedClient];
OfflineObjects *applicationSync = [sdk getOfflineObjects];
KNYSuccessCompletionHandler onSuccess = ^void(id object){
//Operation to be performed on successful sync.
};
KNYFailureCompletionHandler onFailure = ^void(id object){
//Operation to be performed on sync failure.
};
KNYProgressCompletionHandler 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];