Cognos Analytics and JQuery

Yesterday we took a peek at the new implementation of Javascript in Cognos Analytics. Let’s recap:

First off: why would we want to use JQuery? A very readable article arguing about it can be found here – also read the comments there. Since Cognos 11 is forcing its users to use modern web browsers a few advantages are gone, but I still like to work with JQuery anyways.

Due to the fact that RequireJS is used, we can pretty simple check which libraries come out of the box with cognos – we only have to look in the folder webcontent\bi\lib and see all Javascript libraries used in Cognos. There is even a jquery version integrated, namely 2.1.1 (in R4). No need to add our own library (except if you want/need a different version). There is also no need to use NoConflict anymore, fyi.

I took the example from the last article and added a simple JQuery example:

define( ['jquery'], function($) {
function PageModule() {};

PageModule.prototype.show = function( oPage ) {

$('.example1').text('Yada yada yada.');
};

return PageModule; });

Note the differences: You need to declare the plugin you want to use (jquery) and how you want to communicate with it ($). You can access any plugin stored in the RequiredJS folder this way. The line

$('.example1').text('Yada yada yada.'); 

is accesing the text element of every item with the class ‘example1’ and replaces its text with Yada yada yada.

For my example I created a new report, used the page module property and added an html item. Inside I included the following code:

<div class="jquery_test">This is a test message which should be 
 replaced immediately by JQuery.</div>

As you might have noticed by now, I’m using a class instead of an id to access the div. The reason for that is Cognos: ids are overwritten and won’t be shown in the html code. So you either use class or you create your own custom attribute (in HTML5 you would prefix this with data, e.g. data-myid).

If you did everything right and run your report you will notice the text changed and you successfully popped your JQuery & Cognos Analytics cherry.

So far, so good! More to follow.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s