OnlineObjectService Class

Provides methods that perform operations acting on the Quantum Fabric endpoint, including basic CRUD, metadata, and binary-related functions. An instance of OnlineObjectService is returned by the getObjectService Method when the second parameter specifies {"access":"online"}.

Methods

The following methods are used by the OnlineObjectService class and its instantiations.

create Method

Creates an object in the Quantum Fabric endpoint.

Syntax

create(options, successCallback, failureCallback);

Parameters

Parameter Description
options

JSON object with the mandatory parameter "dataObject" which must be an instance of the kony.sdk.dto.DataObject Class.

You can also configure httpRequestOptions and xmlHttpRequestOptions in this parameter. For more information, refer to HTTP Options.

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

Example

var objSvc = kony.sdk.getCurrentInstance().getObjectService("serviceName", {
    "access": "online"
}); 
var dataObject = new kony.sdk.dto.DataObject("ObjectName"); 
dataObject.addField("field1", "value1"); 
var options = {
    "dataObject": dataObject
}; 
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.

update Method

Updates an object in the Quantum Fabric endpoint.

Syntax

update(options, successCallback, failureCallback);

Parameters

Parameter Description
options

JSON object with the mandatory parameter "dataObject", which must be an instance of the kony.sdk.dto.DataObject Class

You can also configure httpRequestOptions and xmlHttpRequestOptions in this parameter. For more information, refer to HTTP Options.

successCallback

Function invoked when the operation succeeds, with the number of records updated

failureCallback Function invoked when the operation fails, with cause of failure

Example

var objSvc = kony.sdk.getCurrentInstance().getObjectService("serviceName", {
    "access": "online"
});

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));
    });

delete Method

Deletes an object in the Quantum Fabric endpoint.

Syntax

deleteRecord(options, successCallback, failureCallback);

Parameters

Parameter Description
options

JSON object with the mandatory parameter "dataObject", which must be an instance of the kony.sdk.dto.DataObject Class

You can also configure httpRequestOptions and xmlHttpRequestOptions in this parameter. For more information, refer to HTTP Options.

successCallback

Function invoked when the operation succeeds, with the number of records deleted

failureCallback Function invoked when the operation fails, with cause of failure

Example

var objSvc = kony.sdk.getCurrentInstance().getObjectService("serviceName", {
    "access": "online"
});

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));
    });

customVerb Method

Performs a custom operation on an object in the Quantum Fabric endpoint.

Syntax

customVerb(verbName, options, successCallback, failureCallback);

Parameters

Parameter Description
verbName Name of the custom verb defined in the Quantum Fabric console
options

JSON object with the mandatory parameter "dataObject", which must be an instance of the kony.sdk.dto.DataObject Class

You can also configure httpRequestOptions and xmlHttpRequestOptions in this parameter. For more information, refer to HTTP Options.

successCallback

Function invoked when the operation succeeds

failureCallback Function invoked when the operation fails, with cause of failure

Example

var objSvc = kony.sdk.getCurrentInstance().getObjectService("serviceName", {
    "access": "online"
});

var dataObject = new kony.sdk.dto.DataObject("ObjectName");
dataObject.addField("field1", "value1");
dataObject.addField("primaryKeyField", "value");

var options = {
    "dataObject": dataObject
};

objSvc.customVerb("verbName", options,
    function(response) {
        kony.print("Custom operation performed: " + JSON.stringify(response));
    },
    function(error) {
        kony.print("Error in custom operation:" + JSON.stringify(error));
    });

fetch Method

Fetches an object from the server.

Syntax

fetch(options, successCallback, failureCallback);

Parameters

Parameter Description
options

JSON object with the mandatory parameter "dataObject", which must be an instance of the kony.sdk.dto.DataObject Class. This instance must have the property selectQueryObject, which is an instance of kony.sdk.dto.SelectQuery, in order to fetch records based on the given criteria.

You can also configure httpRequestOptions and xmlHttpRequestOptions in this parameter. For more information, refer to HTTP Options.

successCallback

Function invoked when the method succeeds, with the number of records fetched

failureCallback Function invoked when fetch fails, with cause of failure

Example

var objSvc = kony.sdk.getCurrentInstance().getObjectService("serviceName", {
    "access": "online"
});

var dataObject = new kony.sdk.dto.DataObject("ObjectName");
var odataUrl = "$filter=fieldname eq value";
dataObject.odataUrl = odataUrl;


var options = {
    "dataObject": dataObject
};

objSvc.fetch(options,
    function(response) {
        kony.print("record: " + response["records"]);
    },
    function(error) {
        kony.print("Failed to fetch: " + JSON.stringify(error));
    });

getMetadataOfAllObjects Method

Gets the metadata associated with the objects defined in the service from the server.

Syntax

getMetadataOfAllObjects(options, successCallback, failureCallback);

Parameters

Parameter Description
options

JSON object with the optional parameter "getFromServer"

You can also configure httpRequestOptions and xmlHttpRequestOptions in this parameter. For more information, refer to HTTP Options.

successCallback

Function invoked when the operation succeeds

failureCallback Function invoked when the operation fails, with cause of failure

Example

var objSvc = kony.sdk.getCurrentInstance().getObjectService("serviceName", {
         "access": "online"
     });

objSvc.getMetadataOfAllObjects({},
function(response) {
  kony.print("Metadata: " + JSON.stringify(response));
},
function(error) {
  kony.print("Error in metadata: " + JSON.stringify(error));
});

getMetadataOfObject Method

Gets the metadata associated with an object defined in the service from the server.

Syntax

getMetadataOfObject(objectName, options, successCallback, failureCallback);

Parameters

Parameter Description
objectName The name of the desired object as defined in the service
options

JSON object with the optional parameter "getFromServer"

You can also configure httpRequestOptions and xmlHttpRequestOptions in this parameter. For more information, refer to HTTP Options.

successCallback

Function invoked when the operation succeeds, with the number of records gotten

failureCallback Function invoked when the operation fails, with cause of failure

Example

var objSvc = kony.sdk.getCurrentInstance().getObjectService("serviceName", {
    "access": "online"
});

objSvc.getMetadataOfObject("objectName", {},
    function(response) {
        kony.print("Metadata: " + JSON.stringify(response));
    },
    function(error) {
        kony.print("Error in metadata: " + JSON.stringify(error));
    });
Parameter Description
options (Refer the Options below) JSON object with the mandatory parameter dataObject, which is an instance of the kony.sdk.dto.DataObject Class,
fileDownloadStartedCallback Callback to be invoked after file download start, this callback is optional.
chunkDownloadCompletedCallback callback invoked after each successful chunk download, this is invoked only when streaming is true. This callback is mandatory if streaming is true.
fileDownloadCompletedCallback Callback invoked after successful file download, with the file path. This is manditory if streaming is false.
downloadFailureCallback Callback invoked in case of download failure.
Key Value Mandatory Default Value
dataObject Instance of kony.sdk.dto.DataObject Yes -
streaming Boolean flag to determine whether the data needed to be given to chunks or a file after download. No false
queryParams provision for user to specify additional query params that need to be sent in the download call. No null
headers Provision for sending custom headers No null
Parameter Description
options (Refer the Options below) JSON object with the mandatory parameter dataObject, which is an instance of the kony.sdk.dto.DataObject Class,
binaryAttributeName Binary field name in the object.
fileDownloadStartedCallback Callback to be invoked after file download start, this callback is optional.
chunkDownloadCompletedCallback callback invoked after each successful chunk download, this is invoked only when streaming is true. This callback is mandatory if streaming is true.
fileDownloadCompletedCallback Callback invoked after successful file download, with the file path. This is manditory if streaming is false.
downloadFailureCallback Callback invoked in case of download failure.
Key Value Mandatory Default Value
dataObject Instance of kony.sdk.dto.DataObject Yes -
streaming Boolean flag to determine whether the data needed to be given to chunks or a file after download. No false
queryParams provision for user to specify additional query params that need to be sent in the download call. No null
headers Provision for sending custom headers No null

getBinaryContent Method

Gets binary content on the server.

Syntax

getBinaryContent(options, successCallback, failureCallback);

Parameters

Parameter Description
options

JSON object with the mandatory parameter "dataObject", which is an instance of the kony.sdk.dto.DataObject Class, and "binaryAttrName", which is the binary field name in the object

You can also configure httpRequestOptions and xmlHttpRequestOptions in this parameter. For more information, refer to HTTP Options.

successCallback

Function invoked when the operation succeeds, with the number of records gotten

failureCallback Function invoked when the operation fails, with cause of failure

Example

var objSvc = kony.sdk.getCurrentInstance().getObjectService("serviceName", {
    "access": "online"
});

var dataObject = new kony.sdk.dto.DataObject("ObjectName");
//primary key details to get media object
dataObject.addField("primary_key", "value");

objSvc.getBinaryContent({
        "dataObject": dataObject,
        "binaryAttrName": "data"
    },
    function(response) {
        kony.print("binary content is : " + JSON.stringify(response));
        frmBinary.downloadImg.isVisible = true;
        frmBinary.downloadImg.base64 = response;
    },
    function(error) {
        kony.print("failed to get binary data : " + JSON.stringify(error));
    });

createBinaryContent Method

Creates binary content on the server.

Syntax

createBinaryContent(options, successCallback, failureCallback);

Parameters

Parameter Description
options

JSON object with the mandatory parameter "dataObject", which is an instance of the kony.sdk.dto.DataObject Class, and "binaryAttrName", which is the binary field name in the object

You can also configure httpRequestOptions and xmlHttpRequestOptions in this parameter. For more information, refer to HTTP Options.

successCallback

Function invoked when the operation succeeds, with the number of records created

failureCallback Function invoked when the operation fails, with cause of failure

Example

var objSvc = kony.sdk.getCurrentInstance().getObjectService("serviceName", {
    "access": "online"
});

var dataObject = new kony.sdk.dto.DataObject("ObjectName");
dataObject.addField("name", "imgName");
dataObject.addField("data", "binaryText");

objSvc.createBinaryContent({
        "dataObject": dataObject,
        "binaryAttrName": "data"
    },
    function(response) {
        kony.print("Binary content created: " + JSON.stringify(response));
    },
    function(error) {
        kony.print("Failed: " + JSON.stringify(error));
    });

updateBinaryContent Method

Updates binary content on the server.

Syntax

updateBinaryContent(options, successCallback, failureCallback);

Parameters

Parameter Description
options

JSON object with the mandatory parameter "dataObject", which is an instance of the kony.sdk.dto.DataObject Class, and "binaryAttrName", which is the binary field name in the object

You can also configure httpRequestOptions and xmlHttpRequestOptions in this parameter. For more information, refer to HTTP Options.

successCallback

Function invoked when the operation succeeds, with the number of records updated

failureCallback Function invoked when the operation fails, with cause of failure

Example

var objSvc = kony.sdk.getCurrentInstance().getObjectService("serviceName", {
    "access": "online"
});

var dataObject = new kony.sdk.dto.DataObject("ObjectName");
dataObject.addField("name", "imgName");
dataObject.addField("data", "binaryText");

objSvc.updateBinaryContent({
        "dataObject": dataObject,
        "binaryAttrName": "data"
    },
    function(response) {
        kony.print("Binary content updated: " + JSON.stringify(response));
    },
    function(error) {
        kony.print("Failed: " + JSON.stringify(error));
    });

 

HTTP Options

The following options can be used while configuring methods of the OnlineObjectService class.

httpRequestOptions Datatype Comments
timeoutIntervalForRequest int This option is a time out value for the HTTP connection. This is also referred to as connection time out value in seconds.
timeoutIntervalForResource int This option is used to give a maximum time in seconds for which the network resource should be kept alive on iOS device. This is only applicable for background network calls and default value is 1 week (7 days) unless specified in options.
enableBackgroundTransfer boolean
(true/false)

This option enables HTTP request calls in background in iOS.

NOTE: This may lead to duplicate transactions in the system and must only be used for GET calls.
iOS internally retries the request to keep the connection alive till it reaches the timeoutIntervalForResource value, which may create duplicate transactions in back end.

 

xmlHttpRequestOptions Datatype Comments
enableWithCredentials boolean
(true/false)
This option allows CORS requests in single-page applications (SPA).