Skip to content

\<object>.get

The \<object>.get API returns all or selected records from the local database.

Note: The column names and values provided as key value pairs are case sensitive.

Volt MX Iris (JavaScrpit)

Signature

<VMXObj>.get(options, successCallback, failureCallback)

Parameters

ParameterTypeDescriptionRequired
options  JSONIf the options parameter is omitted, all records are returned.Yes
successCallbackFunctionThe function is invoked on success with records passed as an argument.Yes
failureCallbackFunctionThe function is invoked on an error with the cause of failure as an argument.Yes

Options Keys

KeysTypeDescriptionRequired
primaryKeysJSON/TableSpecify the primary keys to use for the select query. Use records primary key column names as key and respective values to populate primaryKeys JSON.No
whereConditionAsAStringStringSpecify the where condition for the select query if primary keys are not provided. Key Name: whereConditionAsAString and the value is a string. Note: For Mobile Web and Desktop Web channels, every condition must have a comparison parameter only (=, !=, >, <, >=, <=). Multiple conditions can be clubbed using conjunctions (AND, OR). Values with white spaces are not supported.No
orderByMapJSON elementsSpecifies the way the data should be arranged in ascending/descending order of column name. Key Name: orderByMap and value is an array of the dictionary. Note: In Mobile Web and Desktop Web channels, OrderBy is applicable on one column.No
whereConditionJSONSpecify the where condition for the select query if primary keys are not provided. Key Name: whereCondition and values are column names and their respective values. .No
likeConditionJSON/TableList of column names and their respective values according to which the records are to be fetched. Note: Not supported for Mobile Web and Desktop Web channels.No
projectionColumnsArray List< string>List of column names according to which the records are to be fetched.No
distinctBooleanBoolean value for getting the distinct value of the first projection column passed.No

Return Type

void

Example

//----- Example : Get all  --------
function onGetAllSuccess(records) {
    //records is an array of records. each record is a dictionary.
}

function onGetAllFail(error) {
    voltmx.print("unable to retrieve records from db" + error.code)
}
var categories = new voltmx.sdk.VMXObj("CATEGORY");
//all records of object CATEGORY are returned as an argument to success callback.
categories.get(null, onGetAllSuccess, onGetAllFail)


//------- Example : getall with orderBy clause --------
function onGetAllSuccess(records) {
    //records is an array of records. each record is a dictionary.
}

function onGetAllFail(error) {
    voltmx.print("unable to retrieve records from db" + error.code)
}
var categories = new voltmx.sdk.VMXObj("CATEGORY");
var options = {};
var orderByMap = [];
orderByMap.push({
    "CategoryID": "DESC"
});
orderByMap.push({
    "CategoryName": "ASC"
});
var options = {};
options["orderByMap"] = orderByMap;

//all records of object CATEGORY are returned as an argument to success callback ordered by CategoryID and CategoryName.
categories.get(options, onGetAllSuccess, onGetAllFail);


//------ Example : get by PK  --------
function onGetAllSuccess(records) {
    //records is an array of records. each record is a dictionary.
}

function onGetAllFail(error) {
    voltmx.print("unable to retrieve records from db" + error.code)
}

var categories = new voltmx.sdk.VMXObj("CATEGORY");
var options = {};
//Primary keys or a where clause can be used
var primaryKeys["CategoryID"] = "2233";
options["primaryKeys"] = primaryKeys;

// record with PK CategoryID with value "2233"  of object CATEGORY are returned as an argument to success callback.
categories.get(options, onGetAllSuccess, onGetAllFail)



//---- Example : get by where clause -------- 
function onGetAllSuccess(records) {
    //records is an array of records. each record is a dictionary.
}

function onGetAllFail(error) {
    voltmx.print("unable to retrieve records from db" + error.code)
}
var categories = new voltmx.sdk.VMXObj("CATEGORY");
var whereClause = "Category_PN = '7'";

var options = {};
options["whereConditionAsAString"] = whereClause;

//Invoking get returns  record with Category_PN = 7 .
categories.get(options, onGetAllSuccess, onGetAllFail);



//------- Example : get for projection Columns --------

function onGetSuccess(records) {
    //records is an array of records. Each record is a dictionary.
}
Function onGetFailure(error) {
    VoltMX.print("unable to retrieve records from database" + error.code);
}

var categories = new voltmx.sdk.VMXObj("CATEGORY");

var options = {};
var projectionColumnsList = [];
projectionColumnsList.push("Category_PN");
projectionColumnsList.push("Category_ID");
options["projectionColumns"] = projectionColumnsList;

// Invoking get to get all projection columns passed for records.
categories.get(options, onGetSuccess, onGetFailure);



//------ Example : get for distinct --------

function onGetSuccess(records) {
    //records is an array of records. Each record is a dictionary.
}

Function onGetFailure(error) {
    VoltMX.print("unable to retrieve records from database" + error.code);
}

var categories = new voltmx.sdk.VMXObj("CATEGORY");

var options = {};
options["distinct"] = true;
var projectionColumnsList = [];
projectionColumnsList.push("Category_PN");
options[“projectionColumns”] = projectionColumnsList;

// Invoking get to get all distinct Category_PN records.
categories.get(options, onGetSuccess, onGetFailure);

Android (Java)

Signature

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

Parameters

ParameterTypeDescriptionRequired
optionsHashMap<String, Object>If the options parameter is omitted, all records are returned.Yes
callbackVMXCallbackApplication must implement onSuccess and onFailure methods of VMXCallback interface. Read records are passed as an argument through onSuccess handler. onFailure handler takes cause of failure as an argument.Yes

Options Keys

KeysTypeDescriptionRequired
primaryKeysHashMap<String, Object>Specify the primary keys to use for the select query. Use records primary key column names as key and respective values to populate primaryKeys map.No
whereConditionAsAStringStringSpecify the where condition for the select query if primary keys are not provided. Key Name: whereConditionAsAString and the value is a string.No
orderByMapList of HashMap<String, Object>Specifies the way the data should be arranged in ascending/descending order of column name. Key Name: orderByMap and value is an array of the dictionary.No
whereConditionHashMap<String, Object>Map of column names and their respective values according to which the records are to be fetched.No
likeConditionHashMap<String, Object>Map of column names and their respective values according to which the records are to be fetched.No
projectionColumnsArray List< string>List of column names which are returned.No
distinctBooleanBoolean value for getting the distinct value of the first projection column passed.No

Return Type

void

Example

VMXObj category = new VMXObj("CATEGORY");    


 //----- Example : Get all  --------
 HashMap<String,Object> finalMap = new HashMap<String, Object>();
 category.get(finalMap, new VMXCallback() {
     @Override
     public void onSuccess(Object object) {
         Log.d("Object Read", "Object Read successful for category");       
         ArrayList<HashMap<String, Object>> records = (ArrayList<HashMap<String, Object>>) object;
        for (HashMap<String, String> record : records) {
            Log.d("CATEGORY_DES", record.get("CATEGORY_DES");
         }
     }
     @Override
     public void onFailure(Object error) 
    {
     OfflineObjectsException e=(OfflineObjectsException)error;
        Log.e("Object Read", "Object Read Unsuccessful for category with error :" + e.getMessage());
      }
 });

 //------- Example : getall with orderBy clause --------

 HashMap<String,Object> finalMap = new HashMap<String, Object>();
 HashMap<String, Object> orderByCondition1 = new HashMap<String, Object>();
 HashMap<String, Object> orderByCondition2 = new HashMap<String, Object>();
 orderByCondition1.put("CATEGORY_DES","ASC");
 orderByCondition2.put("CATEGORY_ID","DESC");
 List<HashMap<String, Object>> orderByMap = new ArrayList<HashMap<String, Object>>();
 orderByMap.add(orderByCondition1);
 orderByMap.add(orderByCondition2);
 finalMap.put("orderByMap",orderByMap);

 category.get(finalMap, new VMXCallback() {
     @Override
     public void onSuccess(Object object) {
         Log.d("Object Read", "Object Read successful for category");       
         ArrayList<HashMap<String, Object>> records = (ArrayList<HashMap<String, Object>>) object;
        for (HashMap<String, Object> record : records) {
            Log.d("CATEGORY_DES", record.get("CATEGORY_DES");
         }
     }
     @Override
     public void onFailure(Object error) {
     OfflineObjectsException e=(OfflineObjectsException)error;
        Log.e("Object Read", "Object Read Unsuccessful for category with error :" + e.getMessage());
     }
 });

  //------ Example : get by PK  --------
 HashMap<String,Object> finalMap = new HashMap<String, Object>();
 HashMap<String,Object> primaryKeys = new HashMap<String, Object>();
 primaryKeys.put("CATEGORY_ID","2233");
 finalMap.put("primaryKeys",primaryKeys);
 category.get(finalMap, new VMXCallback() {
     @Override
     public void onSuccess(Object object) {
         Log.d("Object Read", "Object Read successful for category");       
         ArrayList<HashMap<String, String>> records = (ArrayList<HashMap<String, Object>>) object;
        for (HashMap<String, String> record : records) {
            Log.d("CATEGORY_DES", record.get("CATEGORY_DES");
         }
     }
     @Override
     public void onFailure(Object error) {
     OfflineObjectsException e=(OfflineObjectsException)error;
        Log.e("Object Read", "Object Read Unsuccessful for category with error :" + e.getMessage());
     }
 });

 //---- Example : get by where clause -------- 

 HashMap<String,Object> finalMap = new HashMap<String, Object>();
 String whereClause = "CATEGORY_ID = '2233'";
 finalMap.put("whereConditionAsAString",whereClause);
 category.get(finalMap, new VMXCallback() {
     @Override
     public void onSuccess(Object object) {
         Log.d("Object Read", "Object Read successful for category");       
         ArrayList<HashMap<String, Object>> records = (ArrayList<HashMap<String, Object>>) object;
        for (HashMap<String, Object> record : records) {
                Log.d("CATEGORY_DES", record.get("CATEGORY_DES");
         }
     }
     @Override
     public void onFailure(Object error)
    {
     OfflineObjectsException e=(OfflineObjectsException)error;
        Log.e("Object Read", "Object Read Unsuccessful for category with error :" + e.getMessage());
     }
 });



 //--- Example : get for distinct ---  

HashMap<String,Object> finalMap = new HashMap<String, Object>();  
ArrayList<String> projectionColumnsList = new ArrayList<String>();  
projectionColumnsList.add("CATEGORY_DES");  
finalMap.put("distinct", true);  
finalMap.put("projectionColumns" , projectionColumnsList);  
category.get(finalMap, new VMXCallback() {  
     @Override  
     public void onSuccess(Object object) {  
       Log.d("Object Read", "Object Read successful for category");  
       ArrayList<HashMap<String, Object>> records = (ArrayList<HashMap<String, Object>>) object;  
         for (HashMap<String, String> record : records) {  
         Log.d("CATEGORY_DES", record.get("CATEGORY_DES");  
    }  
  }  
     @Override  
     public void onFailure(Object error)  
      {  
       OfflineObjectsException e=(OfflineObjectsException)error;  
        Log.e("Object Read", "Object Read Unsuccessful for category with error :" + e.getMessage());  
   }  
 });

iOS (Objective C)

Signature

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

Parameters

ParameterTypeDescriptionRequired
optionsNSDictionary<NSString*, id>If the options parameter is omitted, all records are returned.Yes
onSuccessVMXSuccessCompletionHandlerThe function is invoked on success with records passed as an argument.Yes
onFailureVMXFailureCompletionHandlerThe function is invoked on an error with the cause of failure as an argument.Yes

Options Keys

KeysTypeDescriptionRequired
primaryKeysNSDictionary<NSString*, id>Specify the primary keys to use for the select query. Use records primary key column names as key and respective values to populate primaryKeys dictionary.No
whereConditionAsAStringNSStringSpecify the where condition for the select query if primary keys are not provided. Key Name: whereConditionAsAString and value is a string.No
orderByMapNSArray< NSDictionary<NSString *, id> *>Specifies the way the data should be arranged in ascending/descending order of column name. Key Name: orderByMap and value is an array of the dictionary.No
whereConditionNSDictionary<NSString *, id>Dictionary of column names and their respective values according to which the records are to be fetched.No
likeConditionNSDictionary<NSString *, id>Dictionary of column names and their respective values according to which the records are to be fetched.No
projectionColumnsNSDictionary<NSString *, id>Dictionary of column names which need to returned.No
distinctBooleanBoolean value for getting the distinct value of the first projection column passed.No

Return Type

void

Example



  //----- Example : Get all  --------

NSError * error;
VMXObj * _categoryObject = [
    [VMXObj alloc] initWithName: @"CATEGORY"
    error: & error
];
//Success handler
VMXSuccessCompletionHandler onSuccess = ^ (id records) {
    NSLog(@"Records read from db successfully");
};

//Failure Handler
VMXFailureCompletionHandler onError = ^ (id error) {
    NSLog(@"Failed to read records with error %@", [error.userInfo localizedDescription]);
};

[_categories get: @{}
    onSuccess: onSuccess onFailure: onError
];

//------- Example : getall with orderBy clause --------

NSError * error;
VMXObj * _categoryObject = [
    [VMXObj alloc] initWithName: @"CATEGORY"
    error: & error
];
NSArray * orderByClause = @ [@{
    "CATEGORY_ID": "DESC"
}, @ {
    "CATEGORY_PK": "ASC"
}];
NSDictionary * options = @ {
    "orderBy": orderByClause
};
//Success handler
VMXSuccessCompletionHandler onSuccess = ^ (id records) {
    NSLog(@"Records read from db successfully");
};

//Failure Handler
VMXFailureCompletionHandler onError = ^ (id error) {
    NSLog(@"Failed to read records with error %@", [error.userInfo localizedDescription]);
};

[_categories get: options onSuccess: onSuccess onFailure: onError];

//------ Example : get by PK  --------

NSError * error;
VMXObj * _categoryObject = [
    [VMXObj alloc] initWithName: @"CATEGORY"
    error: & error
];
NSDictionary * primaryKeys = @ {@
    "CATEGORY_ID": "2233"
};
NSDictionary * options = @ {
    "primaryKeys": primaryKeys
};
//Success handler
VMXSuccessCompletionHandler onSuccess = ^ (id records) {
    NSLog(@"Records read from db successfully");
};

//Failure Handler
VMXFailureCompletionHandler onError = ^ (id error) {
    NSLog(@"Failed to read records with error %@", [error.userInfo localizedDescription]);
};

[_categories get: options onSuccess: onSuccess onFailure: onError];


//---- Example : get by where clause --------

NSError * error;
VMXObj * _categoryObject = [
    [VMXObj alloc] initWithName: @"CATEGORY"
    error: & error
];
NSString * whereClause = "CATEGORY_ID = '2233'";
NSDictionary * options = @ {
    "whereClause": whereClause
};
//Success handler
VMXSuccessCompletionHandler onSuccess = ^ (id records) {
    NSLog(@"Records read from db successfully");
};

//Failure Handler
VMXFailureCompletionHandler onError = ^ (id error) {
    NSLog(@"Failed to read records with error %@", [error.userInfo localizedDescription]);
};

[_categories get: options onSuccess: onSuccess onFailure: onError];


//------ Example: get for distinct -------

NSError * error;
VMXObj * _categoryObject = [
    [VMXObj alloc] initWithName: @"CATEGORY"
    error: & error
];
NSMutableDictionary * options = [
    [NSMutableDictionary alloc] init
];
NSMutableArray * projectionColumnList = [NSMutableArray new];
[projectionColumnsList addObject: @"Category_PN"]
[options setValue: YES forKey: @"distinct "];
[options setValues: projectionColumnList forKey: @"projectionColumns"];

//Success handler
VMXSuccessCompletionHandler onSuccess = ^ (id records) {
    NSLog(@"Records read from db successfully");
};

//Failure Handler
VMXFailureCompletionHandler onError = ^ (id error) {
    NSLog(@"Failed to read records with error %@", [error.userInfo localizedDescription]);
};

[_categories get: options onSuccess: onSuccess onFailure: onError];

Note: If more than one key amongst primaryKeys, whereCondition and whereConditionAsAString are passed in options, the records are fetched in the following priority primaryKeys > whereCondition > whereConditionAsAString. Applicable for all platforms.

Note: If both whereCondition and likeCondition are passed in options, the records are fetched in the following priority: whereCondition> likeCondition. Applicable for all platforms.