0
votes

I'm using IBM MobileFirst to create an app. I've created an HTTP Adapter and now I'm working on the invocation of the response within my main.js file. Here is the invokeProcedure call (the invocationData var calls the adapter and the procedure within that adapter):

    WL.Client.invokeProcedure(invocationData,{
       onSuccess : loadSuccess(),
       onFailure : loadFailure(),
    });

Now, I've defined a loadSuccess() and a loadFailure() function (declared before the invocation) as such (simple for testing purposes):

    var loadSuccess = function(result){
       alert("success");
       alert(result.invocationResult);
    }

    var loadFailure = function(result){
       alert("failure");
       alert(result.invocationResult);
    }

However, while "success" and "failure" will flash, "result" is coming back as null. Every tutorial I have seen as used these methods with success, so I am confused as to why my similar implementation is not working. Furthermore, the invokeProcedure function seems to be calling and flashing the results of both the success and failure options!

My adapter returns an appropriate response when I just test that, so why isn't the invocation of the data working correctly? IBM documentation is not very clear, so I appreciate any and all suggestions!

EDIT:

I updated main.js to the following code:

    function loadSuccess(result){
      alert("success");
    }

    function loadFailure(result) {
      alert("failure");
    }

 function testFunc(userid, password) {
     var invocationData = {
        adapter : 'myAdapter',
        procedure : 'myProc',
        parameters : [ userid, password ],
    };

    WL.Client.invokeProcedure(invocationData,{
       onSuccess : loadSuccess,
       onFailure : loadFailure
   });
}

When I test my adapter, by simply calling it, the response is successful and contains all the response information I want. So why isn't onSuccess being called here?

3
please provide the following : adapter code - authenticationConfig.xml - main.js - Sami
A link to the documentation for the auth config developer.ibm.com/mobilefirstplatform/documentation/… - Radio

3 Answers

1
votes

Likely you need to remove the param brackets from the onSuccess and onFailure declarations, otherwise it runs the functions when assigned rather than when needed:

WL.Client.invokeProcedure(invocationData,{
   onSuccess : loadSuccess,
   onFailure : loadFailure
});
0
votes

Since you're using "var" to define your onSuccess/onFailure callbacks make sure they're in the same scope. Try providing inline callbacks, e.g.

WL.Client.invokeProcedure(invocationOptions, {
   onSuccess: function(data){ alert....},
   onFailure: function(data){ alert....}
})
0
votes

You have to declare initOptions.js , main.js and messages.js in the html file that will use the controller that points to your adapter ..

else the invokeProcedure will be undifined

just go to your html file and but this code in the end of body tag directly before closing tag

<script src="js/initOptions.js"></script>
<script src="js/main.js"></script>
<script src="js/messages.js"></script>