COGNOiSe.com - The IBM Cognos Community

IBM Cognos Analytics Platform => Cognos Analytics => Reporting => Topic started by: Sunchaser on 14 May 2020 12:19:18 PM

Title: Custom control - JS resource not loaded
Post by: Sunchaser on 14 May 2020 12:19:18 PM
Hi all,

-- on Cognos 11.1.5 --

We have a report using custom controls and where we are using some external resources in order to display the data in some nice graphical way (like 3d.js for example).
We are respecting the examples we found and we are building our JS files like:

define(['https://our_site/ibmcognos/samples/someFolder/someResource.js'], function() {

function myObject() { };

myObject.prototype.setData= function(oControlHost, oDataStore) {
// do something here
};

myObject.prototype.draw= function(oControlHost, oDataStore) {
// do something here
};

return myObject;
});


Problem: when the report is run for the first time on a computer, it appears that we get an error as if the code in the JS file was executed before the resource "someResouce.js" (here, for the example only) was loaded.
Let's say we would load jQuery, then we would get an error message like:  "$" doesn't exist ..etc.
Now, after refreshing the page or re-running the report. The problem is gone. Which means to me that the resource is somewhere in the cache.
Why do we have this and how to avoid this? 
This is quite critical, to be honest ...

My understanding is that Cognos is using requireJS and the "define" function is part of that library. Is it correct?
In this case, while reading this "The function will be called to define the module once all dependencies have loaded. " from here: http://requirejs.org/docs/api.html#define, I don't understand why we are facing this issue.

Any help / advice is welcome,
Thanks!
Title: Re: Custom control - JS resource not loaded
Post by: Sunchaser on 26 May 2020 10:58:12 AM
Hi All,

This issue should be solved now, at least all people actually testing don't have any error messages.
What I have found is the following:
. I have observed that when jquery.ui or jquery.dataTables is loaded, then automatically the jquery library (available in lib/jquery/3.3.1/jquery) is loaded - even if this library is not mentioned explicitly.
As we were not aware of this, and we were loading explicitly another jquery resource (version 3.4.1), the two libraries were conflicting.

I'm not sure if this behavior - lib/jquery/3.3.1/jquery loaded implicitly - is due to the requireJS configuration in the Cognos "bundleManifest.js" file. I get no clear answer from IBM Support yet, and looking at the last message I received, I'm not sure I would get any clear information. But let's see ...

Any advice / explanation on this is welcome, even if now not "urgent" as it was..
Cheers!