<objectService>.startSync
The <objectService>.startSync API performs sync for all objects under the object service.
- 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.
Quantum Visualizer (JavaScript)
Signature
KNYObjSvc.startSync(syncOptions, successCallback, failureCallback, progressCallback)
Parameters
Parameter | Type | Description | Required |
syncOptions | 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. |
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. Refer Offline Objects Getting Started guide for more details about sync progress events. NOTE: Not applicable for Mobile Web and Desktop Web channels. If app developer passes this parameter in the options, it will be ignored. |
No |
Sync Options
Options | Type | Descriptions | Required |
---|---|---|---|
filter | JSON |
The filter is a valid OData filter string that allows downloading specific records based on the supplied criteria. When the sync is performed at object service-level, filters are supplied for all objects/entities of that service for which filter criteria needs to be applied as a key-value pair (object name, OData filter string) as shown in the sample code. All records are downloaded for those objects with no or invalid OData filter. |
No |
downloadBatchSize | Number/String |
downloadBatchSize option defines record based batching in downloads. Care should be taken to provide appropriate batch size (number of records) based on backend’s ability to support the same. downloadBatchsize is 500 (records) by default . NOTE:
|
No |
uploadBatchSize | Number/String |
uploadBatchSize option defines record based batching in uploads. uploadBatchSize is 50 (records), by default. Default batch size is assumed if the supplied value is <=0. NOTE: Supported for Mobile Web and Desktop Web channels from V8 SP4 Fix Pack 28 onwards. |
No |
getSyncStats | String |
The getSyncStats option is used to get sync stats information through sync success callback. This option takes two values true or false. Sync stats information is not returned to the user if the getSyncStats option is not supplied or set to false or an invalid value. |
No |
syncType | String |
downloadOnly will download the changes from the server. Change on the client side will not be pushed to the sever. NOTE: Sync will move to the error state, if any other value is provided other than the above mentioned values. |
No |
uploadRequestQueryParams | JSON |
The uploadRequestQueryParams option is used to pass the query parameters in upload network requests. NOTE:
|
No |
downloadRequestQueryParams | JSON |
The downloadRequestQueryParams is used to pass the query parameters in download network requests. NOTE:
|
No |
downloadReconciliationRequired | Boolean |
This parameter specifies if download reconciliation is required or not. Download reconciliation is used to compare primary keys present in backend with application database primary keys for an object. In scenarios where there are no pending edits, it is advisable to perform startSync by setting downloadReconciliationRequired to false (as in the case of initial sync). downloadReconciliationRequired is set to true, by default. NOTE:
|
No |
preserveBatchContext | Boolean |
preserveBatchContext specifies whether to preserve the batchContext of last successful download batch. If batchContext is preserved, the successive download call resumes from the last successful batch, else it starts from the first batch again.
preserveBatchContext is set to false, by default. NOTE: This parameter is not supported for Windows, Mobile Web, and Desktop Web channels. |
No |
Return Type
void
Example
function successCallback(object) { //Handle sync success response. } function failureCallback(error) { //Handle sync failure response. } function progressCallback(object) { //Handle sync progress response. } try { var syncObject = new kony.sdk.KNYObjSvc("Organization"); var syncOptions = {}; //Set uploadRequestQueryParams to be sent during sync in syncOptions. syncOptions.uploadRequestQueryParams = { "LocationID": "32001", "SiteID": "2" }; //Set filters to be applied during download on multiple objects syncOptions.filter = { "Employee": "EmployeeID eq 2", "Department": "Name eq 'Human Resource'" }; //Set upload BatchSize. syncOptions.uploadBatchSize = "200"; //Set getSyncStats to receive sync stats on sync success. syncOptions.getSyncStats = "true"; //Set syncType to perform a sync session syncOptions.syncType = "uploadOnly"; //Supplying call back to receive sync progress events too syncObject.startSync(syncOptions, successCallback, failureCallback, progressCallback); } catch (err) { //Handles Exception. }
Android (Java)
Signature
void <KNYObjSvc>.startSync(final HashMap<String, Object> syncOptions, final KNYCallback syncCallback, final KNYProgressCallback progressCallback) throws Exception
Parameters
Parameter | Type | Description | Required |
syncOptions | HashMap<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.
|
Yes |
syncCallback | KNYCallback | Application implements onSuccess and onFailure methods of KNYCallback interface. | Yes |
progressCallback | KNYProgressCallback | Application implements onProgress method of KNYProgressCallback interface if progress callback is supplied. | No |
Sync Options
Options | Type | Descriptions | Required |
---|---|---|---|
filter | HashMap<String, Object> |
The filter is a valid OData filter string that allows downloading specific records based on the supplied criteria. When the sync is performed at the object service-level, filters are supplied for all objects/entities of that service for which filter criteria needs to be applied as a key-value pair (object name, OData filter string) as shown in the sample code. All records are downloaded for those objects with no or invalid OData filter. |
No |
downloadBatchSize | Number/String |
The downloadBatchSize option defines record based batching in downloads. Care should be taken to provide appropriate batch size (number of records) based on backend’s ability to support the same. downloadBatchSize is 500 (records) by default. NOTE: For SAP as backend, the BatchSize specifies the packet size in bytes |
No |
uploadBatchSize | Number/String |
uploadBatchSize option defines record based batching in uploads. uploadBatchSize is 50(records) by default. Default batch size is assumed if the supplied value is <=0. |
|
getSyncStats | String |
The getSyncStats option is used to get sync stats information through sync success callback. This option takes two values true or false. Sync stats information is not returned to the user if getSyncStats option is not supplied or set to false or an invalid value. |
No |
syncType | String | downloadOnly will download the changes from the server. Change on the client side will not be pushed to the sever. uploadOnly will upload the changes from the client device to the server. Changes on the server will not be downloaded. fullSync will perform both upload and download from the client device to the server and vice-versa. NOTE: Sync will move to the error state, if any other value is provided other than the above mentioned values. |
No |
uploadRequestQueryParams | HashMap<String, String> |
The uploadRequestQueryParams option is used to pass the query parameters in upload network requests. NOTE: The keys and values in the Hashmap must be of the string data type. |
No |
downloadRequestQueryParams | HashMap<String, String> |
The downloadRequestQueryParams is used to pass the query parameters in download network requests. NOTE: The keys and values in the Hashmap must be of the string data type. |
No |
downloadReconciliationRequired | Boolean |
This parameter specifies if download reconciliation is required or not. Download reconciliation is used to compare primary keys present in backend with application database primary keys for an object. In scenarios where there are no pending edits, it is advisable to perform startSync by setting downloadReconciliationRequired to false (as in the case of initial sync). downloadReconciliationRequired is set to true, by default. |
No |
preserveBatchContext | Boolean |
preserveBatchContext specifies whether to preserve the batchContext of last successful download batch. If batchContext is preserved, the successive download call resumes from the last successful batch, else it starts from the first batch again.
preserveBatchContext is set to false, by default. |
No |
Return Type
void
Example
try { //Create an instance of KNYObjSvc KKNYObjSvc syncObject = new KNYObjSvc("Organization"); HashMap < String, Object > syncOptions = new HashMap < String, Object > (); //Set downloadRequestQueryParams to be applied during download on multiple objects HashMap < String, String > downloadRequestQueryParams = new HashMap < String, String > (); downloadRequestQueryParams("LocationID", "32001"); downloadRequestQueryParams("SiteID", "2"); syncOptions.put("downloadRequestQueryParams", downloadRequestQueryParams); //Set filters to be applied during download on multiple objects HashMap < String, Object > filters = new HashMap < String, Object > (); filters.put("Employee", "EmployeeID eq 2"); filters.put("Department", "Name eq ‘Human Resource’"); syncOptions.put("filter", filters); //Set download BatchSize. syncOptions.put("downloadBatchSize", "100"); //Set getSyncStats to receive sync stats on sync success. syncOptions.put("getSyncStats", "true"); //Set syncType to perform a sync session syncOptions.put("syncType", "downloadOnly"); //Supplying call back to receive sync progress events too syncObject.startSync(syncOptions, new KNYCallback() { @Override public void onSuccess(Object object) { Log.d("ObjectServiceSync", "ObjectService sync successful"); } @Override public void onFailure(Object error) { OfflineObjectsException e = (OfflineObjectsException) error; Log.e("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.e("ObjectServiceSync", "ObjectService sync failed with error:" + e.getMessage()); }
iOS (Objective C)
Signature
void <KNYObjSvc> startSync:(NSDictionary <NSString *, id> *)syncOptions onSuccess:(KNYSuccessCompletionHandler)onSuccess onFailure:(KNYFailureCompletionHandler)onFailure onProgress:(KNYProgressCompletionHandler)onProgress;
Parameters
Parameter | Type | Description | Required |
syncOptions | NSDictionary<NSString*, id> | A user can provide options to customize sync behavior. For example, Filters, download batch size etc, see Sync Options section for supported options. Refer Offline Objects Getting Started guide for more details. | 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 |
Sync Options
Options | Type | Descriptions | Required |
---|---|---|---|
filter | NSDictionary<NSString*, id> |
The filter is a valid OData filter string, allows downloading specific records based on the supplied criteria. When a sync is performed at object service level, filters should be supplied for all objects/entities of that service for which filter criteria needs to be applied as a key-value pair (object name, OData filter string) as shown in the sample code. All records are downloaded for those objects with no or invalid OData filter. |
No |
downloadBatchSize | NSNumber/NSString |
The downloadBatchSize option defines record based batching in downloads. Care should be taken to provide appropriate BatchSize (number of records) based on backend’s ability to support the same. downloadBatchSize is 500 (records) by default. NOTE: For SAP as backend, the BatchSize specifies the packet size in bytes.
|
No |
uploadBatchSize | NSNumber/NSString |
uploadBatchSize option defines record based batching in uploads. uploadBatchSize is 50 (records) by default. Default BatchSize is assumed if the supplied values<=0. |
No |
getSyncStats | NSString |
The getSyncStats option is used to get sync stats information through sync success callback. This option takes two values true or false. Sync stats information is not returned to the user if getSyncStats option is not supplied or set to "false" or an invalid value. |
No |
syncType | String | downloadOnly will download the changes from the server. Change on the client side will not be pushed to the sever. uploadOnly will upload the changes from the client device to the server. Changes on the server will not be downloaded. fullSync will perform both upload and download from the client device to the server and vice-versa. NOTE: Sync will move to the error state, if any other value is provided other than the above mentioned values. |
No |
uploadRequestQueryParams | NSDictionary<NSString*, id> |
The uploadRequestQueryParams option is used to pass query parameters in the upload network requests. NOTE: The keys and values in the NSDictionary must be of the string data type. |
No |
downloadRequestQueryParams | NSDictionary<NSString*, id> |
The downloadRequestQueryParams option is used to pass query parameters in download network requests. NOTE: The keys and values in the NSDictionary must be of the string data type. |
No |
downloadReconciliationRequired | Boolean |
This parameter specifies if download reconciliation is required or not. Download reconciliation is used to compare primary keys present in backend with application database primary keys for an object. In scenarios where there are no pending edits, it is advisable to perform startSync by setting downloadReconciliationRequired to false (as in the case of initial sync). downloadReconciliationRequired is set to true, by default. |
No |
preserveBatchContext | Boolean |
preserveBatchContext specifies whether to preserve the batchContext of last successful download batch. If batchContext is preserved, the successive download call resumes from the last successful batch, else it starts from the first batch again.
preserveBatchContext is set to false, by default. |
No |
Return Type
void
Example
NSError * error; KNYObjSvc * syncObject = [ [KNYObjSvc alloc] initWithName: @"Organization" error: & error ]; if (error) { NSLog(@"Object Service Object Creation Failed"); } else { 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. }; NSMutableDictionary * syncOptions = [NSMutableDictionary new]; //Set uploadRequestQueryParams to be applied during upload on multiple objects NSMutableDictionary * uploadRequestQueryParams = [NSMutableDictionary new]; uploadRequestQueryParams[@"LocationID"] = @"32001"; uploadRequestQueryParams[@"SiteID"] = @"2"; [syncOptions setObject: uploadRequestQueryParams forKey: @"uploadRequestQueryParams" ]; //Set downloadRequestQueryParams to be applied during download on multiple objects NSMutableDictionary * downloadRequestQueryParams = [NSMutableDictionary new]; downloadRequestQueryParams[@"LocationID"] = @"32001"; downloadRequestQueryParams[@"SiteID"] = @"2"; [syncOptions setObject: downloadRequestQueryParams forKey: @"downloadRequestQueryParams" ]; //Set filters to be applied during download on object NSMutableDictionary * filters = [NSMutableDictionary new]; [filters setObject: @"EmployeeID eq 2" forKey: @"Employee" ]; [filters setObject: @"Name eq ‘Human Resource’" forKey: @"Department" ]; [syncOptions setObject: filters forKey: @"filter" ]; //Set upload and download BatchSize. [syncOptions setObject: @"100" forKey: @"downloadBatchSize" ]; [syncOptions setObject: @"200" forKey: @"uploadBatchSize" ]; //Set getSyncStats to receive sync stats on sync success. [syncOptions setObject: @"true" forKey: @"getSyncStats" ]; //Set syncType to perform a sync session. [syncOptions setObject: @"fullSync" forKey: @"syncType" ]; //Supplying call back to receive sync progress events too. [syncObject startsync: syncOptions onSuccess: onSuccess onFailure: onFailure onProgress: onProgress ]; }
NOTE: For more details on Offline Objects features and options, refer Offline Objects Getting Started Guide.