Kony Sync Framework Getting Started
2
Copyright © 2012 Kony Solutions, Inc. CONFIDENTIAL
Kony Sync Framework Getting Started
3
Copyright © 2012 Kony Solutions, Inc. CONFIDENTIAL
Kony Sync Framework Getting Started
4
Copyright © 2012 Kony Solutions, Inc. CONFIDENTIAL
Kony Sync Framework Getting Started
5
Copyright © 2012 Kony Solutions, Inc. CONFIDENTIAL
Kony Sync Framework Getting Started
6
Copyright © 2012 Kony Solutions, Inc. CONFIDENTIAL
Kony Sync Framework Getting Started
Kony Sync Framework Client ORM API enables developers to access underlying SQL Lite device database eliminating developer overhead of writing explicit queries to access the data. There are various APIs to help the developer meeting their requirements. Platforms supported are iOS, Android, Blackberry & Windows.
The categorization of these APIS is as follows:
Application Level
Object Level
Note:
In this latest version, the API functions are camel casing. If you are using older release version, you need to update your application accordingly.
This set of APIs will help the developer to perform various ORM operations at Application level.
3.1.1
sync.init
This function initializes the creation of device database as well global state for Data synchronization. On successful, the database structure without data will get created in device database. The create client database will be done once and there onwards it will just initialize the global state only. So this function should always be called after App re-start and before any Sync operation to be performed.
3.1.2
Signature
Lua & JavaScript: sync.init (initSuccessCallback , initFailCallback)
3.1.3
Parameters
initSuccessCallback [function] - Optional
Specifies the function which will get invoked on success.
initFailCallback [function] - Optional
Specifies the function which will get invoked on failure.
3.1.4
Platform Availability
Available on all platforms mentioned.
3.1.5
Lua Example function SyncInit()
sync.init(initSuccessCallback , initFailCallback) end function initSuccessCallback(res)
window.Alert(“Sync Initialized”, nil, "info", "Ok", "", "", nil)
7
Copyright © 2012 Kony Solutions, Inc. CONFIDENTIAL
Kony Sync Framework Getting Started end function initFailCallback (err)
window.Alert(“Sync Failed”, nil, "error", "Ok", "", "Error", nil) end
3.1.6
JavaScript Example function showAlert (msg, handler, alertTitle, btnLabel, alertType)
{
var numType = 0;
if (btnLabel == null) btnLabel = "Ok";
if (alertType == "info") numType = constants.ALERT_TYPE_INFO;
else numType = constants.ALERT_TYPE_ERROR;
//Defining basicConf parameter for alert var basicConf = {message: msg,alertType:numType ,alertTitle: alertTitle,yesLabel:btnLabel,noLabel: "", alertHandler: handler};
//Defining pspConf parameter for alert var pspConf = {} kony.ui.Alert(basicConf,pspConf);
} function syncInit()
{
sync.init(initSuccessCallback , initFailCallback);
} function initSuccessCallback()
{ showAlert("Sync Initialized", null,"Success", null, "info");
} function initFailCallback()
{ showAlert("Sync Failed", null,"Error", null, "error");
}
8
Copyright © 2012 Kony Solutions, Inc. CONFIDENTIAL
Kony Sync Framework Getting Started
3.2
This function triggers the synchronization cycle. It receives a set of configuration as input that helps to fine tune the synchronization process to specific application needs.
3.2.1
Client Side Lifecycle Events
9
Copyright © 2012 Kony Solutions, Inc. CONFIDENTIAL
Kony Sync Framework Getting Started
3.2.2
Configuration Parameters
Parameter Name
[Mandatory/Optional]
Parameter Type Description userid [Mandatory] String password [Mandatory] String
Specifies the user identifier to be used to authenticate the user for accessing the Sync Services
Specifies the password to be used to authenticate the user to access the
Sync Services appid [Mandatory] String serverhost [Mandatory] serverport [Mandatory] sessiontasks [Optional]
String
String
JSObject/table
Application identifier for which the data needs to be synchronized
Identifies the server on which the
Sync Services have been deployed.
Typically a DNS (e.g. sync.kony.net) or a String in IP Address format
(10.10.10.4)
Identifies the port on which the Sync
Services have been deployed.
Allows the user to control Sync
Scopes that should be considered for upload and download. It typical follows the below structure.
{
syncscopename = {doupload=true , dowdownload=true}
}
Setting doupload to true indicates that user wants to download the latest changes from the Sync Server.
Setting doupload to true indicates that the user wants to upload the latest changes in the local tables to
10
Copyright © 2012 Kony Solutions, Inc. CONFIDENTIAL
Batchsize
Filterparams
Kony Sync Framework Getting Started
String
JSObject/table the Sync Server. for e.g config.sessiontasks =
{
Scope1 = {doupload = true, dodownload = false},
Scope2 = {doupload = true,dodownload = false}
}
Indicates the number of rows that will be downloaded in one batch from the server. By default this value is set to 500.
Indicates the filter params/values that will be used to filter data for a specific user/device. This helps to ensure that only data relevant to a specific user is sent to the device and thus making the whole process more optimized. It typically follows the below structure
{ScopeName : [{ SyncObjectName :
[{ FilterName : "ProductName",
Value1 : "" , Value2 : "" }] }] } for e.g. config.filterparams = {
PersistentSyncScope : [ { Products : [
{ Name : "ProductName", Value1 :
"%Cha%" } ] } ] } ;
11
Copyright © 2012 Kony Solutions, Inc. CONFIDENTIAL
Kony Sync Framework Getting Started onsyncstart [Optional] Function Indicates a callback that will be called before the synchronization has started. It receives a context object as parameter with the below keys: uploadurl downloadurl onscopestart [Optional] Function onuploadstart [Optional] Function
Indicates the callback that will be called before synchronization for a specific scope is started.It will be called for each Sync Scope defined in the application. It receives a context object parameter with the below keys uploadurl downloadurl currentScope
Indicates a callback that will called before starting the upload for a specific SyncScope. It is called for each SyncScope defined in the application (unless the specific scope has been set the property doupload=false). It receives a context object with the below keys uploadurl downloadurl currentScope lastsynctimestamp uploadsequencenumber
12
Copyright © 2012 Kony Solutions, Inc. CONFIDENTIAL
Kony Sync Framework Getting Started onuploadsuccess [Optional] Function Indicates a callback that will be called after the changes for all the objects within a scope have been uploaded to the Sync Server. ). It receives a context object with the below keys uploadurl downloadurl currentScope lastsynctimestamp uploadsequencenumber uploadcontext –JSObject/table
rowsuploaded (total number of rows uploaded)
rowsinserted (number of rows inserted)
rowsupdated (number of rows updated)
rowsdeleted (number of rows deleted)
Acktotalrows (total number of rows acknowledged by the server.
Will be populated only for Scopes with Sync Strategy OTASync)
Ackinsertedrows (number of inserted rows acknowledged by the server. Will be populated only for
Scopes with Sync Strategy OTASync)
Ackupdatedrows (number of updated rows acknowledged by the server. Will be populated only for
13
Copyright © 2012 Kony Solutions, Inc. CONFIDENTIAL
onbatchprocessingsuccess
[Optional]
14
Kony Sync Framework Getting Started ondownloadstart [Optional] onbatchprocessingstart [Optional]
Function
Function
Function
Scopes with Sync Strategy OTASync)
Ackdeletedrows (number of deleted rows acknowledged by the server. Will be populated only for
Scopes with Sync Strategy OTASync)
Indicates a callback that will be called before downloading the data changes for a specific scope. It receives a context object populated with the below keys: uploadurl downloadurl currentScope lastsynctimestamp
Indicates a callback that is called before downloading a batch of changes from the Sync Server. It is called for each batch that is sent by the server.
Indicates the callback that is called after a batch has been successfully processed by the client. It receives a context object with the below keys: uploadurl downloadurl currentScope lastsynctimestamp uploadsequencenumber batchcontext –JSObject/table
batchrowsdownloaded
Copyright © 2012 Kony Solutions, Inc. CONFIDENTIAL
Kony Sync Framework Getting Started onscopesuccess [Optional] Function
(number of rows downloaded in a specific batch)
rowsinserted (number of rows inserted)
rowsupdated (number of rows updated)
rowsdeleted (number of rows deleted)
Acktotalrows (total number of rows acknowledged by the server.
Will be populated only for Scopes with Sync Strategy PersistentSync)
Ackinsertedrows (number of inserted rows acknowledged by the server. Will be populated only for
Scopes with Sync Strategy
PersistentSync)
Ackupdatedrows (number of updated rows acknowledged by the server. Will be populated only for
Scopes with Sync Strategy
PersistentSync)
Ackdeletedrows (number of deleted rows acknowledged by the server. Will be populated only for
Scopes with Sync Strategy
PersistentSync)
Indicates a callback that will be called once a specific SyncScope has been processed. It will be called for each SyncScope defined in the application. It receives a context
15
Copyright © 2012 Kony Solutions, Inc. CONFIDENTIAL
Kony Sync Framework Getting Started onsyncsuccess [Optional] onsyncerror [Optional]
Function
Function object with the below keys: uploadurl downloadurl currentScope lastsynctimestamp
Indicates a callback that will be called once all the Sync Scopes have been successfully processed by the
Sync client side libraries. . It receives a context object with the below keys: uploadurl downloadurl currentScope lastsynctimestamp
Indicates the callback that will be called for incase the sync process encounters an error. It receives to parameters: errorcode errormsg
3.2.3
Signature
Lua & JavaScript: sync.startSession(config)
3.2.4
Parameters
config [JSObject/table] - Mandatory
Specifies the table to set the configuration parameters.
3.2.5
Platform Availability
Available on all platforms mentioned.
16
Copyright © 2012 Kony Solutions, Inc. CONFIDENTIAL
Kony Sync Framework Getting Started
3.2.6
Lua Example function startSyncSession(config) local config = {}
-- onXXXXDemo is a function which will be called on these callbacks config.onsyncstart = onsyncstartDemo config.onuploadstart = onuploadstartDemo config.onuploadsuccess = onuploadsuccessDemo config.ondownloadstart = ondowloadstartDemo config.ondownloadsuccess = ondownloadsuccessDemo config.onbatchstored = onbatchstoredDemo config.onbatchprocessingstart = onbatchprocessingstartDemo config.onbatchprocessingsuccess = onbatchprocessingsuccessDemo config.onsyncsuccess = onsyncsuccessDemo config.onsyncerror = onsyncerrorDemo config.onscopestart = onscopestartDemo config.onscopeerror = onscopeerrorDemo config.onscopesuccess = onscopesuccessDemo
-- The below values can be passed by the developer end config.userid= "syncadmin"; config.password="SyncAdmin123"; config.appid = "APPIDNorthwind"; config.serverhost ="10.10.10.10"; config.serverport =”8080”;
-- Configure the size of the batch to be downloaded config.batchsize = “1000” // Default value is 500
-- Session level tasks to control at scopes
-- These parameters will help to configure Download or Upload only for a scope config.sessiontasks =
{
Scope1 = {doupload = true, dodownload = false},
Scope2 = {doupload = true,dodownload = false}
}
-- Starting sync session sync.startSession(config)
3.2.7
JavaScript Example function syncStart()
{ var config = {};
17
Copyright © 2012 Kony Solutions, Inc. CONFIDENTIAL
Kony Sync Framework Getting Started
//onXXXXDemo is a function which will be called on these callbacks config.onsyncstart = onsyncstartDemo; config.onscopestart = onscopestartDemo; config.onscopeerror = onscopeerrorDemo; config.onscopesuccess = onscopesuccessDemo; config.onuploadstart = onuploadstartDemo; config.onuploadsuccess = onuploadsuccessDemo; config.ondownloadstart = ondownloadstartDemo; config.ondownloadsuccess = ondownloadsuccessDemo ; config.onbatchprocessingstart = onbatchprocessingstartDemo; config.onbatchprocessingsuccess = onbatchprocessingsuccessDemo; config.onsyncsuccess = onsyncsuccessDemo; config.onsyncerror = onsyncerrorDemo;
//The below values can be passed by the developer config.userid= "syncadmin"; config.password="SyncAdmin123"; config.appid = "APPIDNorthwind"; config.serverhost ="10.10.10.10"; config.serverport =”8080”;
// Configure the size of the batch to be downloaded
config.batchsize=”1000” // Default value is 500
-- Session level tasks to control at scopes
-- These parameters will help to configure Download or Upload only for a scope config.sessiontasks =
{
Scope1 = {doupload = true, dodownload = false},
Scope2 = {doupload = true,dodownload = false}
}
// The sync.startSession command after populating the config object sync.startSession(config);
}
3.3
This method resets the device database by removing all the data and restoring it to a state after sync.init.
3.3.1
Signature
Lua & JavaScript: sync.reset
(successCallback, errorCallback)
18
Copyright © 2012 Kony Solutions, Inc. CONFIDENTIAL
Kony Sync Framework Getting Started
3.3.2
Parameters
successCallback [function] - Optional
Specifies the function which will get invoked on success.
errorCallback [function] - Optional
Specifies the function which will get invoked on error.
3.3.3
Platform Availability
Available on all platforms mentioned.
3.3.4
Lua Example function SyncReset() sync.reset( successCallback , errorFailCallback ) end function successCallback(res) window.Alert(“Sync Reset Success”, nil, "info", "Ok", "", "", nil) end function errorFailCallback (err) window.Alert(“Sync Reset Failed”, nil, "error", "Ok", "", "Error", nil) end
3.3.5
JavaScript Example function syncReset()
{ sync.reset(resetSuccessCallback,resetFailCallback );
} function resetSuccessCallback()
{ showAlert("Sync reset successfully.", null,"Success", null, "info");
} function resetFailCallback()
{ showAlert("Sync reset failed.", null,"Error", null, "error");
}
3.4
This method resets the data to last synchronized state. This can be used to undo the all the client side changes.
19
Copyright © 2012 Kony Solutions, Inc. CONFIDENTIAL
Kony Sync Framework Getting Started
3.4.1
Signature
Lua & JavaScript: sync.rollbackPendingLocalChanges
(successCallback, errorCallback)
3.4.2
Parameters
successCallback [function] - Optional
Specifies the function which will get invoked on success.
errorCallback [function] - Optional
Specifies the function which will get invoked on error.
3.4.3
Platform Availability
Available on all platforms mentioned.
3.4.4
Lua Example function SyncRollbackPendingChanges() sync.rollbackPendingLocalChanges( successCallback , errorFailCallback ) end function successCallback(res) window.Alert(“Sync Rollback Pending Changes Success”, nil, "info", "Ok", "",
"", nil) end function errorFailCallback (err) window.Alert(“Sync Rollback Pending Changes Failed”, nil, "error", "Ok", "",
"Error", nil) end
3.4.5
JavaScript Example function syncRollBack()
{
} function rollbackSuccessCallback()
{ sync.rollbackPendingLocalChanges(rollbackSuccessCallback,rollbackFailCal lback);
} function rollbackFailCallback()
{ showAlert("All recent changes rollbacked successfully.", null,"Success", null, "info");
20
Copyright © 2012 Kony Solutions, Inc. CONFIDENTIAL
Kony Sync Framework Getting Started showAlert("Problem occurred in rollbacking recent changes.", null,"Error", null, "error");
}
3.5
This method retrieves all the rows across all the SyncObjects which have been upoloaded to the server but are still pending acknowledgement from the server.
3.5.1
Signature
Lua & JavaScript: sync.getPendingAcknowledgement
(successCallback, errorCallback)
3.5.2
Parameters
successCallback [function] - Optional
Specifies the function which will get invoked on success.
errorCallback [function] - Optional
Specifies the function which will get invoked on error.
3.5.3
Platform Availability
Available on all platforms mentioned.
3.5.4
Lua Example function SyncGetPendingAcknowledgement() sync.getPendingAcknowledgement( successCallback , errorFailCallback ) end function successCallback(res) window.Alert(“Sync Pending Acknowledgement Success”, nil, "info", "Ok", "",
"", nil) end function errorFailCallback (err) window.Alert(“Sync Pending Acknowledgement Failed”, nil, "error", "Ok", "",
"Error", nil) end
3.5.5
JavaScript Example function fetchPendingAcknowledgement()
{ sync.getPendingAcknowledgement(ackSuccessCallback ,ackFailCallback)
} function ackSuccessCallback()
21
Copyright © 2012 Kony Solutions, Inc. CONFIDENTIAL
Kony Sync Framework Getting Started
{
} function ackFailCallback()
{ showAlert("Sync Pending Acknowledgement Success", null,"Success", null,
"info"); showAlert("Sync Pending Acknowledgement Failed", null,"Error", null,
"error");
}
3.6
This method retrieves all the rows across all the SyncObjects that are pending to be uploaded to the SyncServer.
3.6.1
Signature
Lua & JavaScript: sync.getPendingUpload
(successCallback, errorCallback)
3.6.2
Parameters
successCallback [function] - Optional
Specifies the function which will get invoked on success.
errorCallback [function] - Optional
Specifies the function which will get invoked on error.
3.6.3
Platform Availability
Available on all platforms mentioned.
3.6.4
Lua Example function SyncGetPendingUpload() sync.getPendingUpload( successCallback , errorFailCallback ) end function successCallback(res) end window.Alert(“Sync Pending Upload Success”, nil, "info", "Ok", "", "", nil) function errorFailCallback (err) window.Alert(“Sync Pending Upload Failed”, nil, "error", "Ok", "", "Error", nil) end
3.6.5
JavaScript Example function fetchPendingUpload()
{
22
Copyright © 2012 Kony Solutions, Inc. CONFIDENTIAL
Kony Sync Framework Getting Started sync.getPendingUpload(pendingUploadSuccessCallback, pendingUploadFailCallback)
} function pendingUploadSuccessCallback()
{ showAlert("Sync Pending Upload Success", null,"Success", null, "info");
} function pendingUploadFailCallback()
{ showAlert("Sync Pending Upload Failed", null,"Error", null, "error");
}
This set of APIs will help the developer to perform various ORM operations at a SyncObject level in the application.
The convention <object> below indicates the GlobalName of the SyncObject as specified in the Sync IDE /
SyncConfig file.
4.1
This method retrieves all the rows for a SyncObject.
4.1.1
Signature
Lua & JavaScript: <object>.getAll (successCallback, errorCallback)
4.1.2
Parameters
successCallback [function] - Optional
Specifies the function which will get invoked on success.
errorCallback [function] - Optional
Specifies the function which will get invoked on error.
4.1.3
Platform Availability
Available on all platforms mentioned.
4.1.4
Lua Example function SyncGetAll() product.getAll( successCallback , errorFailCallback ) end function successCallback(res) window.Alert(“Get All Products Success”, nil, "info", "Ok", "", "", nil)
23
Copyright © 2012 Kony Solutions, Inc. CONFIDENTIAL
Kony Sync Framework Getting Started end function errorFailCallback (err) window.Alert(“Get All Products Failed”, nil, "error", "Ok", "", "Error", nil) end
4.1.5
JavaScript Example function syncGetAll()
{
Account.getAll(showAccSuccessCallback,showAccFailCallback)
} function showAccSuccessCallback()
{ showAlert("Get all Accounts success", null,"Success", null, "info");
} function showAccFailCallback()
{ showAlert("Get all Accounts failed", null,"Error", null, "error");
}
4.2
This method retrieves a row corresponding to a specific primary key value of a SyncObject.
4.2.1
Signature
Lua & JavaScript: <object>.getAllDetailsByPK (pk, successCallback, errorCallback)
4.2.2
Parameters
pk - Mandatory
Specify the object’s primary key using which the respective row data needs to be fetched from the database on the particular object. For composite primary keys it has to be a table/JSObject.
successCallback [function] - Optional
Specifies the function which will get invoked on success.
errorCallback [function] - Optional
Specifies the function which will get invoked on error.
4.2.3
Platform Availability
Available on all platforms mentioned.
24
Copyright © 2012 Kony Solutions, Inc. CONFIDENTIAL
Kony Sync Framework Getting Started
4.2.4
Lua Example function SyncGetAllDetailsByPK() product.getAllDetailsByPK( 123 , successCallback , errorFailCallback ) end function successCallback(res) window.Alert(“Get All Product Details By Primary Key Success”, nil, "info",
"Ok", "", "", nil) end function errorFailCallback (err) window.Alert(“Get All Details By Primary Key Failed”, nil, "error", "Ok", "",
"Error", nil) end
4.2.5
JavaScript Example function SyncGetAllDetailsByPK()
{ product.getAllDetailsByPK(123, successCallback , errorFailCallback)
} function successCallback()
{ showAlert("Get All Product Details By Primary Key Success", null,"Success", null, "info");
} function errorFailCallback ()
{ showAlert("Get All Details By Primary Key Failed", null,"Error", null,
}
"error");
4.3
This method creates a new row for a specific SyncObject. This row will be created locally and will sent to server when the user performs sync.startSession
4.3.1
Signature
Lua & JavaScript: <object>.create (object, succCallback, errorCallback)
25
Copyright © 2012 Kony Solutions, Inc. CONFIDENTIAL
Kony Sync Framework Getting Started
4.3.2
Parameters
Object [] - Mandatory
Specify the object that needs to be created in the database.
successCallback [function] - Optional
Specifies the function which will get invoked on success.
errorCallback [function] - Optional
Specifies the function which will get invoked on error.
4.3.3
Platform Availability
Available on all platforms mentioned.
4.3.4
Lua Example local objectProduct = {ProductName=”xyz”, UnitPrice=12.34} function CreateProduct() product.create( objectProduct , successCallback , errorFailCallback ) end function successCallback(res) window.Alert(“Product Created Successfully”, nil, "info", "Ok", "", "", nil) end function errorFailCallback (err) window.Alert(“Product Creation Failed”, nil, "error", "Ok", "", "Error", nil) end
4.3.5
JavaScript Example var objectProduct = {ProductName:”xyz”, UnitPrice:12.34}; function CreateProduct()
{ product.create(objectProduct, successCallback , errorFailCallback);
} function successCallback()
{ showAlert("Product Created Successfully", null,"Success", null,
"info");
} function errorFailCallback ()
{
} showAlert("Product Creation Failed", null,"Error", null, "error");
26
Copyright © 2012 Kony Solutions, Inc. CONFIDENTIAL
Kony Sync Framework Getting Started
4.4
This method updates a record using its primary key of an SyncObject.
4.4.1
Signature
Lua & JavaScript: < object>.updateByPK (pk, succCallback, errorCallback)
4.4.2
Parameters
pk [Integer] - Mandatory
Specify the object’s primary key using which the respective row data needs to be updated in the database. For composite primary keys it has to be a table/JSObject.
successCallback [function] - Optional
Specifies the function which will get invoked on success.
errorCallback [function] - Optional
Specifies the function which will get invoked on error.
4.4.3
Platform Availability
Available on all platforms mentioned.
4.4.4
Lua Example local objectProduct = {ProductName=”xyzUpdated”, UnitPrice=15.34} function UpdateProductByPK() product.updateByPK( 123 , objectProduct, successCallback , errorFailCallback ) end function successCallback(res) window.Alert(“Get Product by Primary Key Success”, nil, "info", "Ok", "", "", nil) end function errorFailCallback (err) window.Alert(“Get Product by Primary Key Failed”, nil, "error", "Ok", "",
"Error", nil) end
4.4.5
JavaScript Example var objectProduct = {ProductName:”xyzUpdated”, UnitPrice:15.34}; function UpdateProductByPK()
{
27
Copyright © 2012 Kony Solutions, Inc. CONFIDENTIAL
Kony Sync Framework Getting Started product.updateByPK(123, errorFailCallback)
} function successCallback() objectProduct, successCallback ,
{ showAlert("Get Product by Primary Key Success", null,"Success", null, "info");
} function errorFailCallback (err)
{ showAlert("Get Product by Primary Key Failed", null,"Error", null,
"error");
}
4.5
This API helps to update more than one record for and object using the where clause.
4.5.1
Signature
Lua & JavaScript: <object>.update (whereClause, succCallback, errorCallback)
4.5.2
Parameters
whereclause [String] - Mandatory
Specify the string using which the data from database to be fetched.
successCallback [function] - Optional
Specifies the function which will get invoked on success.
errorCallback [function] - Optional
Specifies the function which will get invoked on error.
4.5.3
Platform Availability
Available on all platforms mentioned.
4.5.4
Lua Example local objectProduct = {ProductName=”xyzUpdated”, UnitPrice=15.34} function UpdateProduct()
28
Copyright © 2012 Kony Solutions, Inc. CONFIDENTIAL
Kony Sync Framework Getting Started product.update(“ where UnitPrice > 10 ”, objectProduct, successCallback , errorFailCallback ) end function successCallback(res) window.Alert(“Update Product Success”, nil, "info", "Ok", "", "", nil) end function errorFailCallback (err) window.Alert(“Update Product Failed”, nil, "error", "Ok", "", "Error", nil) end
4.5.5
JavaScript Example var objectProduct = {ProductName:”xyzUpdated”, UnitPrice:15.34}; function UpdateProduct()
{ product.update(“where UnitPrice > 10”, objectProduct, successCallback , errorFailCallback)
} function successCallback()
{
} showAlert("Update Product Success", null,"Success", null, "info"); function errorFailCallback ()
{
} showAlert("Update Product Failed", null,"Error", null, "error");
4.6
This API helps to delete a record using its primary key of an object.
4.6.1
Signature
Lua & JavaScript: <object>.deleteByPK (pk, succCallback, errorCallback)
4.6.2
Parameters
pk [Integer] - Mandatory
Specify the object’s primary key using which the respective row data needs to be deleted in the database.
successCallback [function] - Optional
29
Copyright © 2012 Kony Solutions, Inc. CONFIDENTIAL
Kony Sync Framework Getting Started
Specifies the function which will get invoked on success.
errorCallback [function] - Optional
Specifies the function which will get invoked on error.
4.6.3
Platform Availability
Available on all platforms mentioned.
4.6.4
Lua Example function DeleteProductByPK() product.deleteByPK( 123 , successCallback , errorFailCallback ) end function successCallback(res) window.Alert(“Deleted Product By Primary Key Success”, nil, "info",
"Ok", "", "", nil) end function errorFailCallback (err) window.Alert(“Delete Product By Primary Key Failed”, nil, "error", "Ok", "",
"Error", nil) end
4.6.5
JavaScript Example function DeleteProductByPK()
{ product.deleteByPK(123, successCallback , errorFailCallback)
} function successCallback()
{ showAlert("Deleted Product By Primary Key Success", null,"Success", null, "info");
} function errorFailCallback ()
{ showAlert("Deleted Product By Primary Key Failed", null,"Error", null, "error");
}
4.7
This API helps to delete a record for this object using the where clause.
30
Copyright © 2012 Kony Solutions, Inc. CONFIDENTIAL
Kony Sync Framework Getting Started
4.7.1
Signature
Lua & JavaScript: <object>.remove (whereclause, succCallback, errorCallback)
4.7.2
Parameters
whereclause [String] - Mandatory
Specify the string using which the data from database to be fetched.
successCallback [function] - Optional
Specifies the function which will get invoked on success.
errorCallback [function] - Optional
Specifies the function which will get invoked on error.
4.7.3
Platform Availability
Available on all platforms mentioned.
4.7.4
Lua Example function DeleteProduct() product.remove((“ where ProductId > 100 ”, successCallback , errorFailCallback ) end function successCallback(res) end window.Alert(“Product Deleted Successfully”, nil, "info", "Ok", "", "", nil) function errorFailCallback (err) window.Alert(“Product Delete Failed”, nil, "error", "Ok", "", "Error", nil) end
4.7.5
JavaScript Example function DeleteProduct()
{ product.remove((“where ProductId > 100”, successCallback , errorFailCallback)
} function successCallback()
{
} showAlert("Product Deleted Successfully", null,"Success", null, "info"); function errorFailCallback ()
{
31
Copyright © 2012 Kony Solutions, Inc. CONFIDENTIAL
Kony Sync Framework Getting Started
} showAlert("Product Delete Failed", null,"Error", null, "error");
4.8
This API helps to fetch all the rows which are pending for upload of an object.
4.8.1
Signature
Lua & JavaScript: <object>.getPendingUpload (succCallback, errorCallback)
4.8.2
Parameters
successCallback [function] - Optional
Specifies the function which will get invoked on success.
errorCallback [function] - Optional
Specifies the function which will get invoked on error.
4.8.3
Platform Availability
Available on all platforms mentioned.
4.8.4
Lua Example function GetPendingUpload() product.getPendingUpload( successCallback , errorFailCallback ) end function successCallback(res) end window.Alert(“Get Pending Upload Success”, nil, "info", "Ok", "", "", nil) function errorFailCallback (err) window.Alert(“Get Pending Upload Failed”, nil, "error", "Ok", "", "Error", nil) end
4.8.5
JavaScript Example function GetPendingUpload()
{
} product.getPendingUpload(successCallback , errorFailCallback) function successCallback()
{ showAlert("Get Pending Upload Success", null,"Success", null, "info");
32
Copyright © 2012 Kony Solutions, Inc. CONFIDENTIAL
Kony Sync Framework Getting Started
} function errorFailCallback ()
{
} showAlert("Get Pending Upload Failed", null,"Error", null, "error");
4.9
This API helps to fetch the pending acknowledgments of an object.
4.9.1
Signature
Lua & JavaScript: <object>.getPendingAcknowledgement (succCallback, errorCallback)
4.9.2
Parameters
successCallback [function] - Optional
Specifies the function which will get invoked on success.
errorCallback [function] - Optional
Specifies the function which will get invoked on error.
4.9.3
Platform Availability
Available on all platforms mentioned.
4.9.4
Lua Example function GetPendingAcknowledgement() product.getPendingAcknowledgement( successCallback , errorFailCallback ) end function successCallback(res) window.Alert(“Get Pending Acknowledgement Success”, nil, "info", "Ok", "", "", nil) end function errorFailCallback (err) window.Alert(“Get Pending Acknowledgement Failed”, nil, "error", "Ok", "",
"Error", nil) end
4.9.5
JavaScript Example function GetPendingAcknowledgement()
{
} product.getPendingAcknowledgement(successCallback , errorFailCallback)
33
Copyright © 2012 Kony Solutions, Inc. CONFIDENTIAL
Kony Sync Framework Getting Started function successCallback()
{ showAlert("Get Pending Acknowledgement Success", null,"Success", null,
"info");
} function errorFailCallback ()
{ showAlert("Get Pending Acknowledgement Failed", null,"Error", null,
"error");
}
4.10
This API helps to rollback the object level pending changes which are pending for synchronization.
4.10.1
Signature
Lua & JavaScript: <object>.rollbackPendingLocalChanges (succCallback, errorCallback)
4.10.2
Parameters
successCallback [function] - Optional
Specifies the function which will get invoked on success.
errorCallback [function] - Optional
Specifies the function which will get invoked on error.
4.10.3
Platform Availability
Available on all platforms mentioned.
4.10.4
Lua Example function RollbackPendingLocalChanges() product.rollbackPendingLocalChanges( successCallback , errorFailCallback ) end function successCallback(res) window.Alert(“Rollback Pending Local Changes Success”, nil, "info", "Ok", "",
"", nil) end function errorFailCallback (err)
34
Copyright © 2012 Kony Solutions, Inc. CONFIDENTIAL
Kony Sync Framework Getting Started window.Alert(“Rollback Pending Local Changes Failed”, nil, "error", "Ok", "",
"Error", nil) end
4.10.5
JavaScript Example function RollbackPendingLocalChanges()
{
} product.rollbackPendingLocalChanges(successCallback , errorFailCallback) function successCallback()
{ showAlert("Rollback Pending Local Changes Success", null,"Success", null, "info");
} function errorFailCallback ()
{ showAlert("Rollback Pending Local Changes Failed", null,"Error", null,
"error");
}
4.11
This API helps to roll back the object level pending changes which are pending for synchronization using its primary key.
4.11.1
Signature
Lua & JavaScript: <object>.rollbackPendingLocalChangesByPK (pk, succCallback, errorCallback)
4.11.2
Parameters
pk [Integer] - Mandatory
Specify the object’s primary key using which the respective row data needs to be rollback in the database.
successCallback [function] - Optional
Specifies the function which will get invoked on success.
errorCallback [function] – Optional
35
Copyright © 2012 Kony Solutions, Inc. CONFIDENTIAL
Kony Sync Framework Getting Started
Specifies the function which will get invoked on error.
4.11.3
Platform Availability
Available on all platforms mentioned.
4.11.4
Lua Example function RollbackPendingLocalChangesByPK() product.rollbackPendingLocalChangesByPK( 123 , successCallback , errorFailCallback ) end function successCallback(res) window.Alert(“Rollback Pending Local Changes Success”, nil, "info", "Ok", "",
"", nil) end function errorFailCallback (err) window.Alert(“Rollback Pending Local Changes Failed”, nil, "error", "Ok", "",
"Error", nil) end
4.11.5
JavaScript Example function RollbackPendingLocalChangesByPK()
{
} function successCallback()
{ product.rollbackPendingLocalChangesByPK(123, errorFailCallback) successCallback ,
} function errorFailCallback ()
{ showAlert("Rollback Pending Local Changes By PK Success", null,"Success", null, "info"); showAlert("Rollback Pending Local Changes By PK Failed", null,"Error", null, "error");
}
36
Copyright © 2012 Kony Solutions, Inc. CONFIDENTIAL
Kony Sync Framework Getting Started
4.12
This API helps to find the object using the wrcondition set by the user
4.12.1
Signature
Lua & JavaScript: <object>.find
(wrcondition, succCallback, errorCallback)
4.12.2
Parameters
• wrconditon [String] - Mandatory
Query statement to find the object in the database.
• successCallback [function] - Optional
Specifies the function which will get invoked on success.
• errorCallback [function] - Optional
Specifies the function which will get invoked on error.
4.12.3
Platform Availability
Available on all platforms mentioned.
4.12.4
Lua Example function findProducts() product.find(wcs,successCallback,errorFailCallback ) end function successCallback(res) if(nil~=res and #res>0) then local wcs = "where " for i,v in pairs(res) do if(i==1) then wcs = wcs .. "ProductID='" .. v. ProductID.. "'" else wcs = wcs .. " or ProductID ='" .. v. ProductID.. "'" end end function errorFailCallback (err) window.Alert(“Find ProductID failed”, nil, "error", "Ok", "",
"Error", nil) end function loadProducts( )
{
37
Copyright © 2012 Kony Solutions, Inc. CONFIDENTIAL
Kony Sync Framework Getting Started
//gblEmployeeID is global Employee ID var wcs = "where EmployeeID = " + gblEmployeeID;
EmployeeTerritories.find(wcs, loadEmpTerritoriesSuccCallback, loadEmpTerritoriesErrCallback);
} function loadEmpTerritoriesSuccCallback( res ){
"'"; kony.print("loadEmpTerritoriesSuccCallback" + res); if((null != res && res.length > 0)){ var wcs = "where "; for ( i in res ){ var v = res[ kony.decrement( i ) ]; if((i == 0))
{ wcs = wcs + "TerritoryID='" + v.TerritoryID +
} else
{ wcs = wcs + " or TerritoryID='" + v.TerritoryID + "'";
}
}
}
} function loadEmpTerritoriesErrCallback()
{ kony.ui.Alert(msgNoTerritory,
null,
"info",
"Ok",
"",
"",
null);
4.13
This API helps to retrieves all the records from the related object(XXX) corresponding to the current primary key.
38
Copyright © 2012 Kony Solutions, Inc. CONFIDENTIAL
Kony Sync Framework Getting Started
4.13.1
Signature
Lua & JavaScript: <object>.getXXX (pk, succCallback, errorCallback)
4.13.2
Parameters
pk [Integer] - Mandatory
Specify the object’s primary key using which the respective row data needs to be fetched from the database.
successCallback [function] - Optional
Specifies the function which will get invoked on success.
errorCallback [function] - Optional
Specifies the function which will get invoked on error.
4.13.3
Platform Availability
Available on all platforms mentioned.
4.13.4
Lua Example
E.g.: If there is a relationship from Order to OrderDetails the below function will retrieve all the OrderDetails corresponding to that order. function GetOrderDetails()
<object>.getOrderDetails( 123 , successCallback , errorFailCallback ) end function successCallback(res) end window.Alert(“Get Order Details Success”, nil, "info", "Ok", "", "", nil) function errorFailCallback (err) window.Alert(“Get Order Details Failed”, nil, "error", "Ok", "", "Error", nil) end
{
}
4.13.5
JavaScript Example function GetOrderDetails()
{
}
Order.getOrderDetails(123, successCallback , errorFailCallback); function successCallback() showAlert("Get Order Details Success", null,"Success", null, "info");
39
Copyright © 2012 Kony Solutions, Inc. CONFIDENTIAL
Kony Sync Framework Getting Started function errorFailCallback ()
{
} showAlert("Get Order Details Failed", null,"Error", null, "error");
40
Copyright © 2012 Kony Solutions, Inc. CONFIDENTIAL