2
votes

I am using IBM Worklight Developer Edition 5.0.5 to try to create simple(HTML and Adapter) application, but facing unresolved problem.

This could be a same problem which is not answered in old forum: http://www.ibm.com/developerworks/forums/thread.jspa?threadID=460738

[Environment] OS: Windows7 64bit(Japanese locale), Eclipse: 4.2.1, Worklight: Developer Edition 5.0.5

[Description] I created Worklight Project in my Eclipse, without any external libraries like jQuery mobile nor Dojo. I added HTTP Adapters and SQL Adapters into this Project. Both seems to work fine when I try 'Run As .. -> Invoke Worklight Procedure'. Both returned expected JSON. So I don't think there would be a problem in Adapters.

But when I call those adapters from HTML file, I got "Uncaught TypeError: Cannot use 'in' operator to search for 'SUPPORT_COOKIES' in null" error in worklight.js(line:2380).

[My code]

var invocationData = { adapter : 'SQLAdapter', procedure : 'getCount', parameters : [] };

WL.Logger.debug( "1: invocationData = " + invocationData );
WL.Client.invokeProcedure( invocationData, { onSuccess: loadFeedsSuccess, onFailure: loadFeedsFailure });

WL.Logger.debug( "2: loadFeeds" );

function loadFeedsSuccess( result ){ WL.Logger.debug( "3: success: result = " + result ); }

function loadFeedsFailure( result ){ WL.Logger.debug( "4: failure: result = " + result ); }

[My debug console output]

1: invocationData = [object Object] worklight.js:1112

Uncaught TypeError: Cannot use 'in' operator to search for 'SUPPORT_COOKIES' in null worklight.js:2380

wlclient init started worklight.js:1112

before: app init onSuccess worklight.js:1112

after: app init onSuccess worklight.js:1112

wlclient init success

So it seems only first WL.Logger.debug() is called successfully, but WL.Client.invokeProcedure() seems to cause above Uncaught TypeError, and it just failed(not call success-case callback, nor failure-case callback).

This is a SQL Adapter case, but when I tryed to use HTTP Adapter, the result was same(failed in WL.Client.invokeProcedure()). Again, both returns appropriate result when I try 'Run As .. -> Invoke Worklight Procedure'.

My console says this failure happens in line 2380 of worklight.js:

2379: isEnabled : function(field) {

2380: return !!(field in profile && profile[field]);

2381: }

So I have no idea what would be wrong with my code. Are there any idea/information for this problem? Thanks for advance.

Added Same error was happened in Mac OSX environment too.

3
I found a resolution. Please see my own answer below. Thanks.user2133963

3 Answers

2
votes

I have found what caused my problem.

When accessing adapter, I edited my javascript inside of HTML file directly, using <script> tag at very bottom of autogenerated <script> tags, and tried to create initial page. I believe that is not appropriate way for Worklight. I am not sure what was wrong exactly, but my javascript code could be loaded before everything prepared.

Now I changed my code. I moved my javascript, which used to be inside of HTML, to very bottom of wlCommonInit() function in (Projectname).js. Currently it seems to work fine with no error message like before, and retrieves expected information via adapter. This might be an appropriate way.

1
votes

Calls to Worklight APIs like WL.Client.invokeProcedure and WL.Logger.debug should take place only after wlCommonInit is called.

wlCommonInit resides in your application's main JavaScript file (your-project\your-application\js\application-name.js).

1
votes

To resolve such kind of issue, we need to check when we are invoking the first adapter call. We need to delay the adapter call for some more seconds like 1000ms. Then your application will run as you like it.

setTimeout(function(){
$(document).ready(function() {

    var invocationData = {
            adapter : 'Contract', 
            procedure : 'GetDropDownListForLogin'
    };
    console.log("Invocation data:" +invocationData);
    var options = {
            onSuccess : OnLogindataSucess,
            onFailure : OnLoginFail,
            };

    WL.Client.invokeProcedure(invocationData,options);


});

},1000);

Please use the following way for the first adapter to call it will resolve your issue.