0

I am using IBM Worklight v6.2.

I want to invoke a procedure on a click of a button to return details from a sql database.

HTML

<div id ="page">
    <h1> Hi Welcome User</h1>
    <input type="submit"  id="user" onclick="loadFeeds()" value="Submit">
    <span id="result"></span>
</div>

JavaScript

 function loadFeeds(){
     var invocationData = {
         adapter:"car1",
         procedure:"getuser",
         parameters:["name","city"]
     };

     WL.Client.invokeProcedure(invocationData,{
         onSuccess :loadFeedsSuccess,
         onFailure :loadFeedsFailure,
     });
}

function loadFeedsSuccess(result) {
    var xyz=result.invocationResult.resultSet[0];
    $("#result").html(xyz.name+" "+xyz.city);
    //$("#result").html(xyz.city);
    //alert(xyz.name);
}

function loadFeedsFailure(result) {
    WL.Logger.debug("failure"); 
}

Adapter JS

var user = WL.Server.createSQLStatement("select name,city from user");

function getuser(){
    return WL.Server.invokeSQLStatement({
        preparedStatement : user,
        parameters : []
    });
}

I want to invoke all the values from the database but am not able to do that

Idan Adar
  • 44,156
  • 13
  • 50
  • 89
Suresh
  • 33
  • 10
  • Your question is not completely clear to me: are you saying that the above works for 1 entry from the database and that you want to do this for all entries in the database? or does it not work at all? if it doesn't work at all, did you try to debug it? 1) right-click the adapter and select "invoke worklight procedure", enter a username and click "ok". do you get the expected result? if not, what error do you get? – Idan Adar Aug 01 '14 at 10:40
  • and if it does work, then: 2) preview the application in chrome > open devtools > console > refresh the page, do you see any errors in the console? if yes, what are they? – Idan Adar Aug 01 '14 at 10:42
  • the thing is there are multiple entries in my database,at a time only 1 entry is reflected.the change in entry is reflected on changing the value of result set.ok.i even tried the following code too – Suresh Aug 01 '14 at 10:59
  • function loadFeedsSuccess(result) { WL.Logger.debug("hi"); var xyz =""; var i=''; for(i=0;i<3;i++); { var abc=result.invocationResult.resultSet[i]; xyz+=abc.name+" "; xyz+=abc.city+" "; } $("#result").html(xyz); } – Suresh Aug 01 '14 at 11:01
  • I don't understand. What are you requesting with the adapter and what are you expecting as a response? a list? of what? – Idan Adar Aug 01 '14 at 11:35
  • Iam requesting name and city from adapter..ok...and i am expecting a simple response on html page with all the values retrieved – Suresh Aug 01 '14 at 11:51

1 Answers1

0

See the following almost-identical question: How to retrieve images from existing database using sql/http adapter from worklight application

Maybe this is what you're actually trying to do...
Change loadFeedsSuccess() to:

// Change the append to look like how you need it to be, in your app.
function loadFeedsSuccess(result) {
    for (i = 0; i < result.invocationResult.resultSet.length; i++) {
        var xyz=result.invocationResult.resultSet[i];
        $("#result").append("name: " + xyz.name + " city: " + xyz.city);
    }
}
Community
  • 1
  • 1
Idan Adar
  • 44,156
  • 13
  • 50
  • 89