Vinod Kumar Marupu
Vinod Kumar Marupu

Reputation: 547

IBM MobileFirst 7.0 - Adapter Invocation

Can we send multiple records at a time to Adapter and also can we send object to Adapter. here is the sample Adapter code:

var addStatement = WL.Server.createSQLStatement("insert into MSS (ENO,ENAME,ESALARY) values (?, ?, ?)");
function addSQLAdapterDemo(param0,param1,param2) {
return WL.Server.invokeSQLStatement({
    preparedStatement : addStatement,
    parameters : [param0,param1,param2]
});

}

Main.js in Client side javascript:

$('button#InsertData').on('click', function () {
  var invocationData = {
  adapter : 'SQLAdapterDemo', 
  procedure : 'addSQLAdapterDemo', 
  parameters : [5,'Raj',25000][6,'karan',25000],
  compressResponse: true
};
WL.Client.invokeProcedure(invocationData);

In the Above code I pass three params can we send data like this. And Aslo Can We send object to Adapter. the object is having those three params.

Upvotes: 1

Views: 198

Answers (1)

Mohammad Ashfaq
Mohammad Ashfaq

Reputation: 1373

You can try this code :

/*---------------------------------
Adapter Code
---------------------------------*/
var addStatement = WL.Server.createSQLStatement("insert into MSS (ENO,ENAME,ESALARY) values (?, ?, ?)");
function addSQLAdapterDemo(allRecords) {

var oneRecord;
for ( var count = 0; count < allRecords.length; count++ ){

    oneRecord = allRecords[count];
    WL.Server.invokeSQLStatement({preparedStatement : addStatement,parameters : [oneRecord.id,oneRecord.name,oneRecord.salary]});

}

/*---------------------------------
Client Code
---------------------------------*/
$('button#InsertData').on('click', function () {

/*Preparing JSON Array*/
    var allRecordJson = [];
    allRecordJson.push({"id":"5", "name" : "Raj", "salary" : "25000"});
    allRecordJson.push({"id":"6", "name" : "Karan", "salary" : "20000"});
/*JSON Array Builded*/

  var invocationData = {
  adapter : 'SQLAdapterDemo', 
  procedure : 'addSQLAdapterDemo', 
  parameters : [allRecordJson],
  compressResponse: true
};
WL.Client.invokeProcedure(invocationData);
}

Upvotes: 3

Related Questions