\<object>.update
The \<object>.update API updates the records that are qualified for the criteria in the local database.
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. |
| 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.
| 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.
| 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);
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*, |