Following the ibm doc and other blogs, I tried to invoke an SQL adapter to display results in a mobile simulator.
Followed the document "Module_06_-_Invoking_Adapter_Procedures_from_the_Client_Applications.pdf".
Following are my code:- Step 1 MOBISQLAdap1-impl.js
var procedure1Statement = WL.Server.createSQLStatement("select * from sqldb.dbo.table1");
function procedure1(param) {
return WL.Server.invokeSQLStatement({
preparedStatement : procedure1Statement,
parameters : [param]
});
}
While invoking the SQL Adapter, it is displaying the results. All good here!!
Step 2: - Created an app named Mobi
Step 3:- common/js/initOptions.js In the common/js/initOptions.js file; uncommented the line and the value is true.
var wlInitOptions = {
// # Should application automatically attempt to connect to Worklight Server on application start up
// # The default value is true, we are overriding it to false here.
connectOnStartup : true,
step 4: common/js/main.js file
function loadSQLRecords(){
var invocationData = {
adapter : 'MOBISQLAdap1',
procedure : 'procedure1',
parameters : []
};
WL.Client.invokeProcedure(invocationData,{
onSuccess : loadSQLQuerySuccess,
onFailure : loadSQLQueryFailure
});
}
function loadSQLQuerySuccess(result){
WL.Logger.debug("Retrieve success" + JSON.stringify(result));
displayFeeds(result.invocationResult.resultSet);
}
function loadSQLQueryFailure(result){
WL.Logger.error("Retrieve failure");
}
Step 5: common/js/index.html file; in the body section
<body id="content" style="display: none;">
<div id="itemsList"></div>
<!--application UI goes here-->
Display of data
<script src="js/initOptions.js"></script>
<script src="js/main.js"></script>
<script src="js/messages.js"></script>
</body>
The SQL adapter values are not displayed in the app while previewing. Did the build and deploy before previewing.
Any help appreciated. Thanks rb
You've omitted from the question the most important code snippet - displayFeeds()
, making this not possible to debug!
In addtion, you do not mention if there are any errors - open the Chrome dev tools > console and see if there are any errors while previewing the app.
Finally, this has been asked many times. Please search.
Here are a few questions dealing with the same question.