Provides methods that perform operations acting on the sync database, including basic CRUD, metadata, and binary-related functions. An instance of OfflineObjectService is returned by the getObjectService Method when the second parameter specifies {"access":"offline"}.
The following methods are used by the OfflineObjectService class and its instantiations.
Creates an object offline in the sync database.
create(options, successCallback, failureCallback);
| Parameter | Description |
|---|---|
| options |
JSON object with the following parameters: "dataObject" - a mandatory parameter which must be an instance of the kony.sdk.dto.DataObject Class "httpRequestOptions" an optional parameter used for configuring thin rich network calls. -or- ""xmlHttpRequestOptions" - an optional parameter used for configuring thin thin network calls. The possible values for these options are: "timeoutIntervalForRequest" - specifies the timeout interval. "timeoutIntervalForResource" - specifies the timeout interval. |
| successCallback |
Function invoked when the operation succeeds, with the primary key of the created object |
| failureCallback | Function invoked when the operation fails, with cause of failure |
var objSvc = kony.sdk.getCurrentInstance().getObjectService("serviceName", {
"access": "offline"
});
var dataObject = new kony.sdk.dto.DataObject("ObjectName");
dataObject.addField("field1", "value1");
var options = {
"dataObject": dataObject,
"httpRequestOptions": {
"timeoutIntervalForRequest": 60,
"timeoutIntervalForResource": 600
}
};
objSvc.create(options,
function(response) {
kony.print("Record created: " + JSON.stringify(response));
},
function(error) {
kony.print("Error in record creation: " + JSON.stringify(error));
});
Note: When using object services for SAP, the general norm is to have character field values stored in upper case. However, if you need to pass in mixed/lower case values for an SAP field, ensure that this field is designated as mixed case in the SAP Add-in LDB workbench.
Updates an object offline in the sync database (local store).
update(options, successCallback, failureCallback);
| Parameter | Description |
|---|---|
| options | JSON object with the mandatory parameter "dataObject", which must be an instance of the kony.sdk.dto.DataObject Class |
| successCallback |
Function invoked when the operation succeeds, with the number of records updated |
| failureCallback | Function invoked when the operation fails, with cause of failure |
var objSvc = kony.sdk.getCurrentInstance().getObjectService("serviceName", {
"access": "offline"
});
var dataObject = new kony.sdk.dto.DataObject("ObjectName")
dataObject.addField("field1", "value1");
dataObject.addField("primaryKeyField", "value");
var options = {
"dataObject": dataObject
};
objSvc.update(options,
function(response) {
kony.print("Record updated: " + JSON.stringify(response));
},
function(error) {
kony.print("Error in record update: " + JSON.stringify(error));
});
Deletes an object offline in the sync database.
deleteRecord(options, successCallback, failureCallback);
| Parameter | Description |
|---|---|
| options | JSON object with the mandatory parameter "dataObject", which must be an instance of the kony.sdk.dto.DataObject Class |
| successCallback |
Function invoked when the operation succeeds, with the number of records deleted |
| failureCallback | Function invoked when the operation fails, with cause of failure |
var objSvc = kony.sdk.getCurrentInstance().getObjectService("serviceName", {
"access": "offline"
});
var dataObject = new kony.sdk.dto.DataObject("ObjectName");
dataObject.addField("field1", "value1");
dataObject.addField("primaryKeyField", "value");
var options = {
"dataObject": dataObject
};
objSvc.deleteRecord(options,
function(response) {
kony.print("Record deleted: " + JSON.stringify(response));
},
function(error) {
kony.print("Error in record deletion: " + JSON.stringify(error));
});
Gets the metadata associated with the objects defined in the service from the local store.
getMetadataOfAllObjects(options, successCallback, failureCallback);
| Parameter | Description |
|---|---|
| options | JSON object with the optional parameter "getFromServer" |
| successCallback |
Function invoked when the operation succeeds, with the number of records updated |
| failureCallback | Function invoked when the operation fails, with cause of failure |
var objSvc = kony.sdk.getCurrentInstance().getObjectService("serviceName", {
"access": "offline"
});
objSvc.getMetadataOfAllObjects({},
function(response) {
kony.print("Metadata: " + JSON.stringify(response));
},
function(error) {
kony.print("Error in metadata: " + JSON.stringify(error));
});
Gets the metadata associated with an object defined in the service from the local store.
getMetadataOfObject(objectName, options, successCallback, failureCallback);
| Parameter | Description |
|---|---|
| objectName | The name of the desired object as defined in the service |
| options | JSON object with the optional parameter "getFromServer" |
| successCallback |
Function invoked when the operation succeeds, with the number of records returned |
| failureCallback | Function invoked when the operation fails, with cause of failure |
var objSvc = kony.sdk.getCurrentInstance().getObjectService("serviceName", {
"access": "offline"
});
objSvc.getMetadataOfObject("objectName", {},
function(response) {
kony.print("Metadata: " + JSON.stringify(response));
},
function(error) {
kony.print("error in metadata: " + JSON.stringify(error));
});
Executes a Select query on the sync database.
executeSelectQuery(queryString, successCallback, failureCallback);
| Parameter | Description |
|---|---|
| queryString | SQL Select query string |
| successCallback |
Function invoked when the operation succeeds, with the number of records operated on |
| failureCallback | Function invoked when the operation fails, with cause of failure |
var objSvc = kony.sdk.getCurrentInstance().getObjectService("serviceName", {
"access": "offline"
});
var queryString = "select * from table";
objSvc.executeSelectQuery(queryString,
function(response) {
kony.print("Metadata: " + JSON.stringify(response));
},
function(error) {
kony.print("Error in metadata::" + JSON.stringify(error));
});
Gets binary content from the sync database.
getBinaryContent(options, successCallback, failureCallback);
| Parameter | Description |
|---|---|
| options | JSON object with the mandatory parameter "dataObject", which is an instance of the kony.sdk.dto.DataObject Class |
| successCallback |
Function invoked when the operation succeeds, with the number of records gotten |
| failureCallback | Function invoked when the operation fails, with cause of failure |
var objSvc = kony.sdk.getCurrentInstance().getObjectService("serviceName", {
"access": "offline"
});
var dataObject = new kony.sdk.dto.DataObject("ObjectName");
//primary key details to get object
dataObject.addField("primarykeyfield1", "value1");
var options = {};
options["dataObject"] = dataObject;
//binary column name to get the binary data
options["binaryAttrName"] = "data";
options["responsetype"] = "base64string/filepath";
//filepath is default if it is not set by developer
objSvc.getBinaryContent(options, successcallback, errorcallback);
function successcallback(response) {
//response will contain base64string or filepath
// based on responsetype
//value provided by the developer.
var content = response["records"][0]["data"];
kony.print("Binary Content: " + JSON.stringify(content));
}
function errorcallback(error) {
kony.print("Error in getBinary: " + JSON.stringify(error));
}
| Copyright © 2020 Kony, Inc. All rights reserved. |