Cognos - Adding jQuery

First off, there are many ways to do this, this is just my thing. I am using Cognos 10.2.2 this method will give you the jQuery library under both report prompt and report pages. I do it this way purely to avoid messy code pasting in HTML elements all over a report (very ugly).

Warning: After a fix pack update, you'll need to reapply, but well worth the trouble. If you build JavaScript API's for Cognos you could embed them similarly.

Location of the jQuery file is up to you, I've placed it in a skin, linked it to a CDN, both have their ups and downs. For this article, I am placing a copy in the webcontent root, right along side cognoslaunch.js.

So get your copy,, drop it in the directory. I am using Windblows for this article and my install is in the drive root not the default location.


Okay, now how to get it into your reports, open the following file p_include_main.xsl.


Navigate down to like line 693, insert the following after the closing </script> tag (a new line, 694). I add the comments so I can find it later, not required but... if you make a lot of edits to existing .xsl, .xml and .xts files like I do, it helps.

<!-- :Human: -->
  <script src="{$webRootURI}/jquery-3.5.1.min.js"><xsl:text>/**/</xsl:text></script>
  <script src="{$webRootURI}/some/path/api.human.js"><xsl:text>/**/</xsl:text></script>
<!-- //:Human: -->

It's an invasive edit, so you'll need to restart Cognos. The only other caveat is you'll need to do the jQuery.noConflict(); thing when writing scripts in your prompts and reports, which I usually embed in my API.

I use jQuery along side the Cognos Prompt API all the time, report writers always want kooler reports...

More from Human