1

Facing a weird issue, the worklight adapter is not able to invoke from emulator. The LogCat gives below error

07-02 20:56:59.063: D/DroidGap(873): onMessage(onNativeReady,null)
07-02 20:56:59.063: D/DroidGap(873): onMessage(onPageFinished,file:///data/data/com.PivMobileNew/files/www/default/PivMobileNew.html#clientListPage)
07-02 20:56:59.513: D/PivMobileNew(873):  --------- $('#clientListPage').bind('pageinit',  function(event){ ------------
07-02 20:57:00.673: E/PivMobileNew(873): [http://10.202.4.254:1028/worklight/apps/services/api/PivMobileNew/android/query] exception. undefined is not a function
07-02 20:57:00.823: D/CordovaLog(873): Uncaught TypeError: undefined is not a function
07-02 20:57:00.823: D/CordovaLog(873): file:///data/data/com.PivMobileNew/files/www/default/wlclient/js/worklight.js: Line 1467 : Uncaught TypeError: undefined is not a function
07-02 20:57:00.823: E/Web Console(873): Uncaught TypeError: undefined is not a function at file:///data/data/com.PivMobileNew/files/www/default/wlclient/js/worklight.js:1467

However while invoking the adapter from common it works fine.

here is the adapter invoking code...

function GetClient(strClientName) {
    var invocationData = {
            adapter : 'PivMobileAdapter'
                ,procedure : 'getClient'
                    ,parameters: [{"ClientName":strClientName}]
    };
    WL.Logger.debug(" --------- entered in function GetClient-------    2c");
    try {
    WL.Client.invokeProcedure(invocationData, {
        onSuccess : handleSuccess,
        onFailure : handleFailure,
    });
    }
    catch (e)
    {   WL.Logger.debug("---inside try catch, error occured while invokingProcedure----");
        WL.Logger.debug(e.message);
    }

    function handleSuccess(result) {
        WL.Logger.debug(" --------- inside handling success invoking procedure $('#searchNew').click(function() -------    2c");
        ...some code here1...
        ...some code here2...
    }

    function handleFailure(result) {
        WL.Logger.debug(" --------- inside handling failure invoking procedure $('#searchNew').click(function() -------    2c");
        ...some code here1...
        ...some code here2...
    }
}

Not sure how to go forward, can anyone help?

Rajiv
  • 47
  • 7
  • 2
    Edit your question with your JavaScript that invokes the adapter procedure. – Idan Adar Jul 02 '13 at 16:01
  • 1
    Seems like its complaining that it cant find the handleSuccess and handleFailure inner functions. – tik27 Jul 02 '13 at 22:13
  • I don't think the app event reaches the procedure invocation part; Please add the entire logcat you get when launching the app. – Idan Adar Jul 14 '13 at 12:02

1 Answers1

0

You have to define your onSuccess and onFailure handler functions before you use the references. You need save your function reference within a variable as well, because your code is already inside a function.

var handleSuccess = function(xxx) {
    // some code
};

var handleFailure = function(xxx) {
    // some code
};
// references need to exist prior to passing them as callback handlers.
WL.Client.invokeProcedure(invocationData, {
        onSuccess : handleSuccess,
        onFailure : handleFailure,
});
MHeiss
  • 107
  • 4
  • tried this, moved the function definition above but still not working. Do callback function needs to be in quotes like 'handleSuccess'? – Rajiv Jul 03 '13 at 09:23
  • I've updated my answer again. Are you sure that your JavaScript function gets called, or is already included when your app calls it? – MHeiss Jul 03 '13 at 13:36
  • this also didn't help. But i have got the problem. – Rajiv Jul 04 '13 at 11:22
  • Thanks all for helping me. – Rajiv Jul 04 '13 at 12:16
  • add internet permission to manifest file and connect the device to internet, in the same network of worklight server – Angelo Jul 04 '13 at 13:29