Skip to content

\<object>.markForUpload

The <object>.markForUpload API selects the changes made to the records and sent to the server. If the markForUpload flag is not enabled, the changes made are deferred from uploading to the server until marked for upload using specific markForUpload APIs.

The markForUpload flag is set to true, by default.

Volt MX Iris (JavaScript)

Signature

<object>.markForUpload(options, successCallback, failureCallback)

Parameters

ParameterTypeDescriptionRequired
optionsJSONA dictionary containing mandatory key primaryKeys which contains the PK (column name and value). In case of a composite PK, the dictionary will contain multiple key-value pairs.Yes
successCallbackFunctionThe function is invoked when the changes are successfully uploaded to the server.Yes
failureCallbackFunctionThe function is invoked when the changes are deferred from uploading to the server.Yes

Options Keys

KeysTypeDescriptionRequired
primaryKeysJSONSpecify the primary keys of the record to select a query. Key Name: primaryKeys and value is a dictionary of primary keys.Yes

Return Type

void

Example

var category = new voltmx.sdk.VMXObj("CATEGORY");
var options = {};
var primaryKeys["CategoryID"] = "1";
options["primaryKeys"] = primaryKeys;
//mark the deferred record for upload with primary key 1
category.markForUpload(options, successCallback, failureCallback);

var category = new voltmx.sdk.VMXObj("CATEGORY");
//mark all the deferred records in the object for upload
category.markForUpload(null, successCallback, failureCallback);


function successCallback() {
    voltmx.print("markForUpload successful");
}

function errorCallback(error) {
    voltmx.print("markForUpload failed " + error.code);
}  

Android (Java)

Signature

<VMXObj>.markForUpload(final HashMap<String, Object> options, final VMXCallback callback)

Parameters

ParameterTypeDescriptionRequired
optionsHashMap<String, Object>key: primaryKeys. Value: HashMap<String, Object>: Pass a hashmap of primary keys and its value. HashMap containing PK (column name and value). In case of a composite PK, the dictionary will contain multiple key-value pairs.Yes
callbackVMXCallbackTakes onSuccess and onFailure methods.Yes

Options Keys

KeysTypeDescriptionRequired
primaryKeysHashMap<String, Object>Specify the primary keys of the record for the select query. Key Name: primaryKeys and respective values to populate primaryKeys map.Yes

Return Type

void

Examples

VMXObj category = new VMXObj("CATEGORY");
HashMap < String, Object > options = new HashMap < String, Object > ();
HashMap < String, Object > primaryKeys = new HashMap < String, Object > ();
primaryKeys.put("CATEGORY_ID", "1");
options.put("primaryKeys", primaryKeys);
//mark the deferred record for upload with primary key 1
category.markForUpload(options, new VMXCallback() {
        @Override
        public void onSuccess(Object object) {
            Log.d("Object markforupload", "Object markforupload Successful ");
        }

        @Override
        public void onFailure(object error) {
            OfflineObjectsException e = (OfflineObjectsException) error;
            Log.e("Object markforupload", "Object markforupload unsuccessful for category with Error :" + e.getMessage());
        }
    }

VMXObj category = new VMXObj("CATEGORY");
//mark all the deferred records in the object for upload
category.markForUpload(null, new VMXCallback() {
        @Override
        public void onSuccess(Object object) {
            Log.d("Object markforupload", "Object markforupload Successful");
        }
        @Override
        public void onFailure(object error) {
            OfflineObjectsException e = (OfflineObjectsException) error;
            Log.e("Object markforupload", "Object markforupload unsuccessful for category with Error :" + e.getMessage());
        }
    }

iOS (Objective C)

Signature

void <VMXObj> markForUpload:(NSDictionary <NSString *, id> *)options 
               onSuccess:(VMXSuccessCompletionHandler)onSuccess 
               onFailure:(VMXFailureCompletionHandler)onFailure

Parameters

ParameterTypeDescriptionRequired
optionsNSDictionarykey: primaryKeys. Value: Dictionary containing PK (column name and value). In case of composite PK, the dictionary will contain multiple key-value pairs.Yes
onSuccessCallbackVMXSuccessCompletionHandlerThe function is invoked when the changes are successfully uploaded to the server.Yes
onFailCallbackVMXFailureCompletionHandlerThe function is invoked when the changes are deferred from uploading the server.Yes

Options Keys

KeysTypeDescriptionRequired
primaryKeysNSDictionary<NSString*, id>Specify the primary keys of the record to select the query. Key name: primaryKeys and value is a dictionary of primary keys.Yes

Return Type

void

Example

NSError error = nil;
VMXObj * _categories = [
    [VMXObj alloc] initWithName: @"CATEGORY"
    error: & error
];
NSDictionary * primaryKeys = @ {@
    "CATEGORY_ID": "1"
};
NSDictionary * options = @ {
    "primaryKeys": primaryKeys
};
//mark the deferred record for upload with primary key 1
[_categories markForUpload: options
    onSuccess: ^ () {
        NSLog(@"Object markforupload successful ");
    }
    onFailure: ^ (id object) {
        OfflineObjectsError * error = (OfflineObjectsError) object;
        NSLog(@"Object markforupload unsuccessful because of error:%@", [error.userInfo
            localizedDescription
        ]);
    }
];

NSError error = nil;
VMXObj * _categories = [
    [VMXObj alloc] initWithName: @"CATEGORY"
    error: & error
];
//mark all the deferred records in the object for upload
[_categories markForUpload: null
    onSuccess: ^ () {
        NSLog(@"Object markforupload");
    }
    onFailure: ^ (id object) {
        OfflineObjectsError * error = (OfflineObjectsError) object;
        NSLog(@"Object markforupload unsuccessful because of error:%@", [error.userInfo
            localizedDescription
        ]);
    }
];

Utility API

The API returns all the deferred records primary keys for a particular object.

Volt MX Iris (JavaScript)

Note: Not supported for Mobile Web, and Desktop Web channels.

Signature

<object>.getUploadDeferredRecordKeys(successCallback, failureCallback)

Example

var category = new voltmx.sdk.VMXObj("CATEGORY");
category.getUploadDeferredRecordKeys(successCallback, failureCallback);

function successCallback(result) {
    for (var pks in result) {
        voltmx.print("deferred records with primary keys " + JSON.stringify(pks));
    }
}

function failureCallback(error) {
    voltmx.print("failed with error " + error.code);
}

Android (Java)

Signature

void <VMXObj>. getUploadDeferredRecordKeys (final VMXCallback callback)

Example

VMXObj category = new VMXObj("CATEGORY");
category.getUploadDeferredRecordKeys(new VMXCallback() {
        @Override
        public void onSuccess(Object result) {
            List < HashMap < String, Object >> pksList = (List < HashMap < String, Object >> ) result;
            for (HashMap < String, Object > pks: pksList) {
                for (Map.Entry < String, Object > e: pks.entrySet()) {
                    Log.d("deferred record with key : " + e.getKey() + "value: "+e.getValue());
                }
            }
        }
    }

    @Override 
    public void onFailure(Object error) {
        OfflineObjectsException e = (OfflineObjectsException) error;
        Log.e("getDeferredUpload", "getDeferredUpload failed with error " + e.getMessage());
    }
});

iOS (Objective C)

Signature

<void> [<VMXObj> getUploadDeferredRecordKeys: (VMXSuccessCompletionHandler) onSuccess
         onFailure: (VMXFailureCompletionHandler) onFailure]

Example

NSError error = nil;
VMXObj * _categories = [
    [VMXObj alloc] initWithName: @"CATEGORY"
    error: & error
];

[_categories getUploadDeferredRecordKeys: onSuccess: onFailure: onFailure];

VMXSuccessCompletionHandler onSuccess = ^ void(id result) {
    NSArray * pks = (NSArray * ) result;
    for (id obj in pks) {
        for (id key in obj) {
            NSLog(“key % @, value % @“, key, [obj objectForKey: key]);
        }
    }
}

VMXFailureCompletionHandler onFailure = ^ void(id error) {
    NSLog("failed with error " + error.code);
}