Skip to content

<object>.create

The <object>.create API creates a new record in the local database.

Note:

  • If any column is defined as auto-generated, values are not allowed in them unless the trackChanges key is set to false.
  • The record must contain all the mandatory columns and their respective values.
  • The column names and values provided as key value pairs are case sensitive.

Volt MX Iris (JavaScript)

Signature

<VMXObj>.create(record, options, successCallback, failureCallback)

Parameters

ParameterTypeDescriptionRequired
recordJSONSpecify the record to be created in the database under a given object.Yes
optionsJSONOption parameter accepts a HashMap that contains the following options keys: trackChanges markForUpload For more information, refer Options Keys.Yes
successCallbackFunctionThe function is invoked when records are created successfully. Newly created record is retuned through the success callback.Yes
failureCallbackFunctionThe function is invoked on an error with the cause of failure as an argument.Yes

Options

ParameterTypeDescriptionRequired
trackChangesBooleanIf the trackChanges key 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). By default, the key is set to True.No
markForUploadJSONIf markForUpload is set to False, the record changes are not uploaded to the server. By default, the option is set to True.No

Return Type

void

Example

var category = new voltmx.sdk.VMXObj("CATEGORY");
var record = {};

// CATEGORY_ID is the autogenerated primary key
record["CATEGORY_PN"] = Number("7");
record["CATEGORY_DES"] = "Creating a new record";

function successCallback(response) {
voltmx.print("Record created successfully with primary keys: " + response["CATEGORY_ID"]);
}

function errorCallback(error) {
voltmx.print("Create is failed" + JSON.stringify(error));
}
category.create(record, {}, successCallback, errorCallback);

//Disable Change Tracking
var options = {
"trackChanges": false
};
var VMXObject = new voltmx.sdk.VMXObj("CATEGORY");
VMXObject.create(record, options, successCallback, failureCallback);

//Mark for Upload
var options = {
"markForUpload": false
};
category.create(record, options, successCallback, errorCallback);

Android (Java)

Signature

void <VMXObj>.create(final HashMap<String, Object>record, final HashMap<String, Object> options, VMXCallback callback) throws Exception

Parameters

ParameterTypeDescriptionRequired
recordHashMap<String, Object>Specify the record to be created in the database under a given object.Yes
optionsHashMap<String, Object>For future use, supply null or empty HashMap as options.Yes
callbackVMXCallbackApplication must implement onSuccess and onFailure methods of VMXCallback interface. Newly created record is retuned through onSuccess callback and onFailure handler is invoked with cause of failure as an argument in case of error.Yes

Sync Options

ParameterTypeDescriptionRequired
trackChangesBooleanSet the trackChanges key to false, the record level operations are not tracked. Hence, the records are not synced (uploaded). Note: You must provide values for primary key columns when trackChanges is set to false.No
markForUploadHashMapSet the markForUpload to false, the record changes are not uploaded to the server.No

Return Type

void

Example

try {
//Create object in which the record should be created
private VMXObj syncObject = new VMXObj("CATEGORY");

    //CATEGORY_ID is autogenerated primary key
    HashMap < String, Object > newRecord = new HashMap < > ();
    newRecord.put("CATEGORY_PN", "2");
    newRecord.put("CATEGORY_DES", "Vegetables");

    //HashMap for options.
    HashMap < String, Object > ;
    options = new HashMap < > ();
    syncObject.create(newRecord, options, new VMXCallback() {
        @Override
        public void onSuccess(Object response) {
            Log.d("Primary key of the newly created record:" + response.get("CATEGORY_ID"));
        }

@Override
public void onFailure(Object error) {
OfflineObjectsException e = (OfflineObjectsException) error;
Log.e("Object creation failed with error:" + e.getMessage());
}
});
} catch (Exception e) {
Log.e("Object creation failed with error:" + e.getMessage());
}

//Disable change tracking
Hashmap < String, Object > options = new HashMap < > ();
options.put(KSPublicConstants.TRACK_CHANGES, false);
sdkObjectSync.create(record, options, new VMXCallback() {
@Override
public void onSuccess(Object response) {}
@Override
public void onFailure(Object error) {}
});

//Mark for Upload
HashMap < String, Object > ;
options = new HashMap < String, Object > ();
options.put("markForUpload", false);
syncObject.create(newRecord, options, new VMXCallback() {
@Override
public void onSuccess(Object response) {}
@Override
public void onFailure(Object error) {}
});

iOS (Objective C)

Signature

void <VMXObj> create:(NSDictionary <NSString _, id> _) record
options:(NSDictionary <NSString _, id> _)options
onSuccess:(VMXSuccessCompletionHandler)onSuccess
onFailure:(VMXFailureCompletionHandler)onFailure

Parameters

ParameterTypeDescriptionRequired
recordNSDictionary<NSString*, id>Specify the record to be created in the database under a given object.Yes
optionsNSDictionary<NSString*, id>For future use, supply null or empty NSDictionary as options.Yes
onSuccessVMXSuccessCompletionHandlerThe function is invoked when records are created successfully. Newly created record is retuned through the success callback.Yes
onFailureVMXFailureCompletionHandlerThe function is invoked on an error with the cause of failure as an argument.Yes

Sync Options

ParameterTypeDescriptionRequired
trackChangesBooleanSet the trackChanges key to false, the record level operations are not tracked. Hence, the records are not synced (uploaded). Note: You must provide values for primary key columns when trackChanges is set to false.No
markForUploadNSDictionary<NSString*, id>Set the markForUpload to false, the record changes are not uploaded to the server.No

Return Type

void

Examples

VMXObj _ _categoryObject = [
[VMXObj alloc] initWithName: @"CATEGORY"
error: & error
];
NSMutableDictionary _ newRecord = [NSMutableDictionary new]
newRecord[@"CATEGORY_DES"] = @"New record";
newRecord[@"CATEGORY_PN"] = @"7";

[_categoryObject create: newRecord options: @{}
onSuccess: ^ (id response) {
NSLog(@"Create record is successful, primary key: %@", [response objectForKey: @"CATEGORY_ID"]);
}
onFailure: ^ (id object) {
OfflineObjectsError \* error = (OfflineObjectsError) object;
NSLog(@"Create record Failed with error %@", [error.userInfo localizedDescription]);
}
];

//Disable change tracking
NSDictionary < NSString _ , id > _ options = @ {
VMXCONSTANTS_TRACK_CHANGES: @NO
};
[sdkObjectSync create: record options: options onSuccess: ^ (id object) {}
onFailure: ^ (id object) {}
];

//Mark for Upload
NSDictionary < NSString _ , id > _ options = @ {
VMXCONSTANTS_MARK_FOR_UPLOAD: @NO
};
[sdkObjectSync create: 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 the CUD operations on a record. You must not update the value of change tracking flag in between the CUD operations on a record.
  • When you set both markForUpload and trackChanges flags, an error is reported as these are mutually exclusive options.
  • The change tracking option for Cascade Delete is also applicable for the child records.
  • For Hierarchical Objects, you must provide a proper value for both parent and child record operations.