<object>.update
The <object>.update API updates the records that are qualified for the criteria in the local database.
Note:
- Not supported for Windows channel.
- The column names and the values provided as key value pairs are case sensitive.
Volt MX Iris (JavaScript)
Signature
<VMXObj>.update(record, options, successCallback, failureCallback)
Parameters
Parameter | Type | Description | Required |
record | JSON | A dictionary containing column name and value pairs which are to be updated. | Yes |
options | JSON | The options parameter accepts a JSON that has the following options keys primaryKeys whereCondition whereConditionAsAString trackChanges trackIntermediateUpdates markForUpload For detailed information, refer Options Keys. If the options parameter is null or empty, all the records are updated. | Yes |
successCallback | Function | The function is invoked when the records are updated successfully. | Yes |
failureCallback | Function | The function is invoked on an error with the cause of failure as an argument. | Yes |
Options Keys
Keys | Type | Description | Required |
---|---|---|---|
primaryKeys | JSON | Specify the primary keys of the record to be updated. Key Name: primaryKeys and values are column names and their respective values. | No |
whereCondition | JSON | Specify the where condition for the update query. Key Name: whereCondition and values are column names and their respective values. | No |
whereConditionAsAString | String | Specify the where condition for the update query. Key Name: whereConditionAsAString and the value is a string. > Note: For SPA/Desktop Web channels, each condition must have only one comparison operator (=,!=,>,<,>=,<=). Multiple conditions can be clubbed using conjunctions (AND, OR). Values containing whitespaces are not supported. | No |
trackChanges | Boolean | If trackChanges is set to False, the record level operations are not tracked. When the option is set to false, the CUD operations performed on a record are not synced (uploaded). The key is set to True, by default. Note: Not supported for SPA/Desktop Web channels. | No |
trackIntermediateUpdates | Boolean | If trackIntermediateUpdates is set to False, it enables to track the latest update performed on the record. The key is set to True, by default. Note: Not supported for SPA/Desktop Web channels. | No |
markForUpload | Boolean | If markForUpload is set toFalse, the record changes are not uploaded to the server. The key is set to True, by default. Note: Not supported for SPA/Desktop Web channels. | No |
syncLatestObjectSnapshot | Boolean | This option, when turned on (set to True), ensures that only the most recent update is sent for a specific primary key, rather than sending two entries when both create and update operations occur for that key. | No |
Return Type
void
Example
//------- update all records -------
var category = new voltmx.sdk.VMXObj("CATEGORY");
var record = {};
record["CATEGORY_DES"] = "Update existing record";
function successCallback(response) {
//response holds the number of records updated
}
function errorCallback(error) {
voltmx.print("Update failed with error: " + JSON.stringify(error));
}
category.update(record, null, successCallback, errorCallback);
//--------update a record using primary key--------
var category = new voltmx.sdk.VMXObj("CATEGORY");
var options = {};
var record = {};
var primaryKeys = {};
record["CATEGORY_DES"] = "Update existing record";
primaryKeys["CATEGORY_ID"] = "1234";
options["primaryKeys"] = primaryKeys;
function successCallback(response) {
//response holds the number of records updated
}
function errorCallback(error) {
voltmx.print("Update failed with error: " + JSON.stringify(error));
}
category.update(record, options, successCallback, errorCallback);
//------- update by whereCondition-------
var category = new voltmx.sdk.VMXObj("CATEGORY");
var options = {};
var record = {};
var whereClause = {};
whereClause["Category_PN"] = 7;
record["CATEGORY_DES"] = "Update existing record";
options["whereCondition"] = whereClause;
function successCallback(response) {
//response holds the number of records updated
}
function errorCallback(error) {
voltmx.print("Update failed with error: " + JSON.stringify(error));
}
category.update(record, options, successCallback, errorCallback);
//------- update by whereConditionAsAString -------
var category = new voltmx.sdk.VMXObj("CATEGORY");
var options = {};
var record = {};
var whereClause = "Category_PN = '7'";
record["CATEGORY_DES"] = "Update existing record";
options["whereConditionAsAString"] = whereClause;
function successCallback(response) {
//response holds the number of records updated
}
function errorCallback(error) {
voltmx.print("Update failed with error: " + JSON.stringify(error));
}
category.update(record, options, successCallback, errorCallback);
//------- update using Disable change tracking flag - trackIntermediateUpdates ---------
var options = {
"trackIntermediateUpdates": false
};
var VMXObject = new voltmx.sdk.VMXObj("CATEGORY");
VMXObject.update(record, options, successCallback, errorCallback);
//------- update using Disable change tracking flag – trackChanges ---------
var options = {
"trackChanges": false
};
var VMXObject = new voltmx.sdk.VMXObj("CATEGORY");
VMXObject.update(record, options, successCallback, errorCallback);
//------- update using markForUpload flag ---------
var options = {
"markForUpload": false
};
var VMXObject = new voltmx.sdk.VMXObj("CATEGORY");
VMXObject.update(record, options, successCallback, errorCallback);
//------- update using markForUpload flag ---------
var options = {
"markForUpload": false
};
var VMXObject = new voltmx.sdk.VMXObj("CATEGORY");
VMXObject.update(record, options, successCallback, errorCallback);
//------- update using syncLatestObjectSnapshot flag ---------
var options = {
"syncLatestObjectSnapshot": false
};
var VMXObject = new voltmx.sdk.VMXObj("CATEGORY");
VMXObject.update(record, options, successCallback, errorCallback);
Android (Java)
Signature
void <VMXObj>.update(HashMap<String, Object> record,
HashMap<String, Object> options,
final VMXCallback callback) throws Exception
Parameters
Parameter | Type | Description | Required |
record | HashMap<String, Object> | A HashMap containing column name and value pairs which are to be updated. | Yes |
options | HashMap<String, Object> | The options parameter accepts a HashMap with the following option keys: primaryKeys whereCondition whereConditionAsAString trackChanges trackIntermediateUpdates markForUpload For detailed information, refer Options Keys. If the options parameter is omitted, all the records are updated. | Yes |
callback | VMXCallback | Application implements onSuccess and onFailure methods of VMXCallback interface. | Yes |
Options Keys
Keys | Type | Description | Required |
primaryKeys | HashMap<String, Object> | Specify the primary keys of the record to be updated. Key Name: primaryKeys and values are column names and their respective values. | No |
whereCondition | HashMap<String, Object> | Map of column names and their respective values according to which the records are to be updated. | No |
whereConditionAsAString | String | Specify the where condition for the select query. Key Name: whereConditionAsAString and the value is a string. Note: For SPA/Desktop Web channels, each condition must have only comparison parameter (=,!=,>,<,>=,<=). Multiple conditions can be clubbed using conjunctions(AND, OR). Values with whitespaces are not supported. | No |
trackChanges | Boolean | If trackChanges is set to False, the record level operations are not tracked. When the option is set to false, the CUD operations performed on a record are not synced (uploaded). The key is set to True, by default. | No |
trackIntermediateUpdates | Boolean | If trackIntermediateUpdates is set to False. The option enables us to track the latest update performed on the record. The option is set to True, by default. | No |
markForUpload | Boolean | If markForUpload is set to false, the record changes are not uploaded to the server. The option is set to True, by default. | No |
Return Type
void
Example
//Update record with a primary key
VMXObj category = new VMXObj("CATEGORY");
HashMap < String, Object > record = new HashMap < String, Object > ();
record.put("CATEGORY_PN", "7");
record.put("CATEGORY_DES", "new updated description");
HashMap < String, Object > primaryKeys = new HashMap < > ();
primaryKeys.put("CATEGORY_ID", "123");
HashMap < String, Object > options = new HashMap < > ();
options.put("primaryKeys", primaryKeys);
try {
category.update(record, options, new VMXCallback() {
@Override
public void onSuccess(Object object) {
Log.d("Object Update", "Object Update Successful for category");
}
@Override
public void onFailure(Object error) {
OfflineObjectsException e = (OfflineObjectsException) error;
Log.e("Object Update", "Object Update Unsuccessful for category with Error :" + e.getMessage());
}
});
catch (Exception e) {
Log.e("Object Update".
"Object Update Unsuccessful with error: " + e.getMessage());
}
}
//Update record with composite primary key
HashMap < String, Object > record = new HashMap < String, Object > ();
record.put("CATEGORY_PN", "7");
record.put("CATEGORY_DES", "new updated description");
HashMap < String, Object > primaryKeys = new HashMap < > ();
primaryKeys.put("CATEGORY_KEY1", "123");
primaryKeys.put("CATEGORY_KEY2", "124");
HashMap < String, Object > options = new HashMap < > ();
options.put("primaryKeys", primaryKeys);
try {
category.update(record, options, new VMXCallback() {
@Override
public void onSuccess(Object object) {
Log.d("Object Update", "Object Update Successful for category");
}
@Override
public void onFailure(Object error) {
OfflineObjectsException e = (OfflineObjectsException) error;
Log.e("Object Update", "Object Update Unsuccessful for category with Error :" + e.getMessage());
}
});
} catch (Exception e) {
Log.e("Object Update", "Object Update Unsuccessful for category with Error :" + e.getMessage());
}
//Update record using whereCondition
VMXObj category = new VMXObj("CATEGORY");
HashMap < String, Object > record = new HashMap < String, Object > ();
record.put("CATEGORY_PN", "7");
record.put("CATEGORY_DES", "new updated description");
HashMap < String, Object > whereClause = new HashMap < > ();
whereClause.put("CATEGORY_ID", "123");
HashMap < String, Object > options = new HashMap < > ();
options.put("whereCondition", whereClause);
try {
category.update(record, options, new VMXCallback() {
@Override
public void onSuccess(Object object) {
Log.d("Object Update", "Object Update Successful for category");
}
@Override
public void onFailure(Object error) {
OfflineObjectsException e = (OfflineObjectsException) error;
Log.e("Object Update", "Object Update Unsuccessful for category with Error :" + e.getMessage());
}
});
} catch (Exception e) {
Log.e("Object Update".
"Object Update Unsuccessful with error: " + e.getMessage());
}
//Update record using whereConditionAsAString
VMXObj category = new VMXObj("CATEGORY");
HashMap < String, Object > record = new HashMap < String, Object > ();
record.put("CATEGORY_PN", "7");
record.put("CATEGORY_DES", "new updated description");
String whereClause = "CATEGORY_ID = 123";
HashMap < String, Object > options = new HashMap < > ();
options.put(“whereConditionAsAString”, whereClause);
try {
category.update(record, options, new VMXCallback() {
@Override
public void onSuccess(Object object) {
Log.d("Object Update", "Object Update Successful for category");
}
@Override
public void onFailure(Object error) {
OfflineObjectsException e = (OfflineObjectsException) error;
Log.e("Object Update", "Object Update Unsuccessful for category with Error :" + e.getMessage());
}
});
} catch (Exception e) {
Log.e("Object Update".
"Object Update Unsuccessful with error: " + e.getMessage());
}
//Disable change tracking - trackIntermediateUpdates
HashMap < String, Object > options = new HashMap < > ();
options.put(KSPublicConstants.TRACK_INTERMEDIATE_UPDATES, false);
category.update(record, options, new VMXCallback() {
@Override
public void onSuccess(Object object) {}
@Override
public void onFailure(Object object) {}
});
//Disable change tracking - trackChanges
HashMap < String, Object > options = new HashMap < > ();
options.put(KSPublicConstants.TRACK_CHANGES, false);
category.update(record, options, new VMXCallback() {
@Override
public void onSuccess(Object object) {}
@Override
public void onFailure(Object object) {}
});
//Mark for Upload
HashMap < String, Object > options = new HashMap < > ();
options.put(KSPublicConstants.MARK_FOR_UPLOAD, false);
category.update(record, options, new VMXCallback() {
@Override
public void onSuccess(Object object) {}
@Override
public void onFailure(Object object) {}
});
iOS (Objective C)
Signature
void <VMXObj>.update:(NSDictionary<NSString *, id> *)record
options:(NSDictionary<NSString *, id> *)options
onSuccess:(VMXSuccessCompletionHandler)onSuccess
onFailure:(VMXFailureCompletionHandler)onFailure
Parameters
Parameter | Type | Description | Required |
record | NSDictionary<NSString*, id> | A dictionary containing column name and value pairs which are to be updated. | Yes |
options | NSDictionary<NSString*, id> | The options parameter accepts a NSDictionary with the following option keys: - primaryKeys - whereCondition - whereConditionAsAString - trackChanges - trackIntermediateUpdates - markForUpload For detailed information, refer Options Keys. If the options parameter is null or empty, all the records are updated. | Yes |
onSuccess | VMXSuccessCompletionHandler | The function is invoked when records are updated successfully. | Yes |
onFailure | VMXFailureCompletionHandler | The function is invoked when updating records fail with the cause of failure. | Yes |
Options Keys
Keys | Type | Description | Required |
primaryKeys | NSDictionary<NSString*, id> | Specify the primary keys of the record to be updated. Key Name: primaryKeys and the values are column names and their respective values. | No |
whereCondition | NSDictionary <NSString*, id> | Dictionary of column names and their respective values according to which the records are to be updated. | No |
whereConditionAsAString | NSString | Specify the where condition for the update query. Key Name: whereConditionAsAString and the value is a string. | No |
trackChanges | Boolean | If trackChanges is set to False, the record level operations are not tracked. When the option is set to false, the CUD operations performed on a record are not synced (uploaded). The option is set to True, by default. | No |
trackIntermediateUpdates | Boolean | If trackIntermediateOptions is set to False, it enables to track the latest update performed on the record. The option is set to True, by default. | No |
markForUpload | Boolean | If markForUpload is set to false, the record changes are not uploaded to the server. The option is set to True, by default. | No |
Return Type
void
Examples
// Update record with a primary key
VMXObj * _categories = [
[VMXObj alloc] initWithName: @"CATEGORY"
error: & error
];
NSMutableDictionary * recordToUpdate = [NSMutableDictionary new];
recordToUpdate[@"CATEGORY_DES"] = @"updated description";
recordToUpdate[@"CATEGORY_PN"] = @"3";
NSMutableDictionary * options = [NSMutableDictionary new];
NSMutableDictionary * primaryKeys = [NSMutableDictionary new];
primaryKeys[@"CATEGORY_ID"] = @"112";
options[@"primaryKeys"] = primaryKeys;
[_categories update: recordToUpdate
options: options
onSuccess: ^ (id object) {
NSLog(@"Update record succeded");
}
onFailure: ^ (id object) {
OfflineObjectsError * error = (OfflineObjectsError) object;
NSLog(@"Update record failed with error %@", [error.userInfo localizedDescription]);
}
];
// Update record with composite primary key
VMXObj * _categories = [
[VMXObj alloc] initWithName: @"CATEGORY"
error: & error
];
NSMutableDictionary * recordToUpdate = [NSMutableDictionary new];
recordToUpdate[@"CATEGORY_DES"] = @"updated description";
recordToUpdate[@"CATEGORY_PN"] = @"3";
NSMutableDictionary * options = [NSMutableDictionary new];
NSMutableDictionary * primaryKeys = [NSMutableDictionary new];
primaryKeys[@"PRIMARY_KEY1"] = @"123";
primaryKeys[@"PRIMARY_KEY2"] = @"222";
options[@"primaryKeys"] = primaryKeys;
[_categories update: recordToUpdate
options:
onSuccess: ^ (id object) {
NSLog(@"Updated successfully");
}
onFailure: ^ (id object) {
OfflineObjectsError * error = (OfflineObjectsError) object;
NSLog(@"Update record failed with error %@", [error.userInfo localizedDescription]);
}
];
// Update record using whereCondition
VMXObj * _categories = [
[VMXObj alloc] initWithName: @"CATEGORY"
error: & error
];
NSMutableDictionary * recordToUpdate = [NSMutableDictionary new];
recordToUpdate[@"CATEGORY_DES"] = @"updated description";
recordToUpdate[@"CATEGORY_PN"] = @"3";
NSMutableDictionary * options = [NSMutableDictionary new];
NSMutableDictionary * whereClause = [NSMutableDictionary new];
whereClause[@"CATEGORY_ID"] = @"112";
options[@"whereCondition"] = whereClause;
[_categories update: recordToUpdate
options: options
onSuccess: ^ (id object) {
NSLog(@"Updated successfully");
}
onFailure: ^ (id object) {
OfflineObjectsError * error = (OfflineObjectsError) object;
NSLog(@"Update record failed with error %@", [error.userInfo localizedDescription]);
}
];
// Update record using whereConditionAsAString
VMXObj * _categories = [
[VMXObj alloc] initWithName: @"CATEGORY"
error: & error
];
NSMutableDictionary * recordToUpdate = [NSMutableDictionary new];
recordToUpdate[@"CATEGORY_DES"] = @"updated description";
recordToUpdate[@"CATEGORY_PN"] = @"3";
NSMutableDictionary * options = [NSMutableDictionary new];
NSString * whereClause = @"CATEGORY_ID = 112";
options[@"whereConditionAsAString"] = whereClause;
[_categories update: recordToUpdate
options: options
onSuccess: ^ (id object) {
NSLog(@"Updated successfully");
}
onFailure: ^ (id object) {
OfflineObjectsError * error = (OfflineObjectsError) object;
NSLog(@"Update record failed with error %@", [error.userInfo localizedDescription]);
}
];
//Disable change tracking - trackIntermediateUpdates
NSDictionary < NSString * , id > * options = @ {
VMXCONSTANTS_TRACK_ INTERMEDIATE_UPDATES: @NO
};
[sdkObjectSync update: record
options: options
onSuccess: ^ (id object) {}
onFailure: ^ (id object) {}
];
//Disable change tracking - trackChanges
NSDictionary < NSString * , id > * options = @ {
VMXCONSTANTS_TRACK_CHANGES_ UPDATES: @NO
};
[sdkObjectSync update: record
options: options
onSuccess: ^ (id object) {}
onFailure: ^ (id object) {}
];
//Mark for Upload
NSDictionary < NSString * , id > * options = @ {
VMXCONSTANTS_MARK_FOR_ UPLOAD: @NO
};
[sdkObjectSync update: record
options: options
onSuccess: ^ (id object) {}
onFailure: ^ (id object) {}
];
Note:
- The trackChanges flag must be used consistently (either always true or always false) for all CUD operations on a record. You must not update the value of "change tracking" flag in between CUD operations on a record.
- When you set both markForUpload and trackChanges flags, an error is reported as these are mutually exclusive options.
- When the user sets both trackIntermediateUpdates and trackChanges flags, an error is reported as these are mutually exclusive options.
- For Hierarchical Objects, you must provide a proper value for both parent and child record operations.
- The primaryKeys, whereCondition, and whereConditionAsAString are considered as the criteria to update a record. Only one criterion is considered at a time and the order is primaryKeys > whereCondition > whereConditionAsAString.
Note: To soft delete a column, mention the softdelete column name. Ensure all the tables have the same softdelete column name. For the offline object service with multiple objects, if the soft delete column is not common for all the objects, instead of using delete API, use the
<object>.update
API and set the softdelete field to true in the device database.