Howto Include Custom Javascript in Cognos 8 by Default

Do you often need to manipulate controls in prompt pages in cognos? Well if you do there is one major point to take in consideration – cognos intrinsic control names. To access any of the cognos prompt controls via javascript you will need to supply the cognos intrinsic control name plus the given name in order to identify the control.

Now imagine its two years down the line and your busy upgrading to a new version of cognos. You run a report and bam, javascript errors abound on your custom prompt page. No worries you fire up firefox/firebug and low and behold cognos have decided to rename their intrinsic controls. You start sweating trying to calculate how may hours its gonna take to go through two years worth of reports to update your javascript.

Well here’s a very easy solution to abstract away this dependency. Follow these steps (Cognos 8+ & Windows, requires admin access on cognos server(s) and a system bounce):

1. Navigate to <congos-install-dir>\webcontent

2. Create a new folder, I will use etc for the this example

3. Create a js file in your newly created dir, mine is <congos-install-dir>\webcontent\etc\etc.js

4. Add some javascript to hold the cognos control names e.g.
var Cognos = {
Dropdown: '_oLstChoices',
Textbox: '_textEditBox'
}

5. Now open the file <congos-install-dir>\templates\ps\prompting\p_include.xsl

6. Search for the text
<xsl:if test="//promptButton or //defaultPromptFooter or //selectValue or //textBox or //selectDate or //selectWithSearch or //selectWithTree or //selectTime or //selectInterval or //selectDateTime or //selectDataSourceSignon">

7. Add a script element below this to include the js file – mine is

<script language="javascript" src="../etc/etc.js" type="text/JavaScript">//leave this comment here to assure we have an explicit end tag for script</script>

8. Save and close, bounce cognos

Now all cognos prompt pages will include this js file, so if cognos one day decides to rename their controls you can modify the names in the js file and your set. Obviously you can take this one step further and create a library providing macros for routine prompt screen javascript stuff.

technorati tags:,

Blogged with Flock