**//------- 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
//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
**// 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**.