IBM Worklight - How To Parse Adapter Response?
This is my stored procedure: CREATE PROCEDURE PROC() BEGIN SELECT * FROM TABLENAME; END// This is my unction to call stored procedure using SQL adapter: function callStored() {
Solution 1:
In your application JavaScript (common\js\main.js), you can have something like the following. In the below code an alert will be displayed with the values of the name
key from the resultSet.
You can also take a look here: use resultset returned by WL.Server.invokeSQLStatement within sql adapter procedure
function wlCommonInit() {
invokeAdapter();
}
function invokeAdapter() {
var invocationData = {
adapter: "your-adapter-name",
procedure: "callStored",
parameters: []
};
WL.Client.invokeProcedure (invocationData, {
onSuccess: invocationSuccess,
onFailure: invocationFailure}
);
}
function invocationSuccess(response) {
var i,
resultSet = response.invocationResult.resultSet;
namesArray = [];
for (i = 0; i < resultSet.length; i++) {
namesArray[i] = resultSet[i].name;
}
alert (JSON.stringify(namesArray));
}
function invocationFailure(response) {
alert (response);
}
You have already asked this here: ibm worklight stored procedure
Why did you not follow through the documentation and learned how to write the above?
Please read the documentation!
Solution 2:
Please read the "Invoking adapter procedures from client applications" and its Exercise and code sample in the Getting started with IBM Worklight page.
function wlCommonInit(){
getUsersInfo();
}
function getUsersInfo(){
var invocationData = {
adapter : 'YOUR_ADAPTER',
procedure : 'YOUR_PROCEDURE',
parameters : []
};
WL.Client.invokeProcedure(invocationData,{
onSuccess : getUsersInfoSuccess,
onFailure : getUsersInfoFailure
});
}
function getUsersInfoSuccess(result){
if (result.invocationResult.Items.length > 0) {
displayUsersInfo(result.invocationResult.Items);
} else {
getUsersInfoFailure();
}
}
function getUsersInfoFailure(result){
alert("Cannot retrieve users info");
}
function displayUsersInfo(items){
var i = 0, usersInfo = '';
for (i = 0; i < items.length; i++) {
usersInfo += ' name: ' + items[i].name;
usersInfo += ' pass: ' + items[i].pass;
usersInfo += ' time_stamp: ' + items[i].time_stamp;
}
alert(usersInfo);
}
Post a Comment for "IBM Worklight - How To Parse Adapter Response?"