\<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
Parameter | Type | Description | Required |
options | JSON | If the options parameter is omitted, all records are returned. | Yes |
successCallback | Function | The function is invoked on success with records passed as an argument. | 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/Table | Specify 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 |
whereConditionAsAString | String | Specify 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 |
orderByMap | JSON elements | 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. Note: In Mobile Web and Desktop Web channels, OrderBy is applicable on one column. | No |
whereCondition | JSON | Specify 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 |
likeCondition | JSON/Table | List 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 |
projectionColumns | Array List< string> | List of column names according to which the records are to be fetched. | No |
distinct | Boolean | Boolean 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
Parameter | Type | Description | Required |
options | HashMap<String, Object> | If the options parameter is omitted, all records are returned. | Yes |
callback | VMXCallback | Application 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
Keys | Type | Description | Required |
primaryKeys | HashMap<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 |
whereConditionAsAString | String | Specify the where condition for the select query if primary keys are not provided. Key Name: whereConditionAsAString and the value is a string. | No |
orderByMap | List 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 |
whereCondition | HashMap<String, Object> | Map of column names and their respective values according to which the records are to be fetched. | No |
likeCondition | HashMap<String, Object> | Map of column names and their respective values according to which the records are to be fetched. | No |
projectionColumns | Array List< string> | List of column names which are returned. | No |
distinct | Boolean | Boolean 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
Parameter | Type | Description | Required |
options | NSDictionary<NSString*, id> | If the options parameter is omitted, all records are returned. | Yes |
onSuccess | VMXSuccessCompletionHandler | The function is invoked on success with records passed as an argument. | Yes |
onFailure | VMXFailureCompletionHandler | The function is invoked on an error with the cause of failure as an argument. | Yes |
Options Keys