Javascript in Cognos
Javascript in Cognos
1 Disclaimer.........................................................................................................................2
2 Introduction.......................................................................................................................3
3 JavaScript Usage for Cognos Prompts.............................................................................3
4 Retrieving prompts...........................................................................................................4
4.1 Standard prompts...........................................................................................4
4.2 Other prompts................................................................................................4
5 Common Actions on Prompts ..........................................................................................5
5.1 Modifying the prompts before the prompt page is displayed........................5
5.1.1 Set a value for a text box.........................................................................5
5.1.2 Select an item in a multiselect List Box..................................................5
5.1.3 Remove the first 2 lines from a Drop Down List prompt.......................5
5.1.4 Enable the “Finish” button......................................................................6
5.2 Running scripts after the user clicks the Finish button..................................7
6 Debugging JavaScript.......................................................................................................9
6.1 Detecting JavaScript errors in Internet Explorer (IE)....................................9
6.2 Using Firebug debugger in Firefox................................................................9
7 References.........................................................................................................................9
7.1 Upgrading JavaScript Applications to IBM Cognos 8.3/8.4.........................9
..........................................................................................................................................9
1
1 Disclaimer
The techniques in this document depend on undocumented and
unsupported aspects of the Cognos 8 Business Intelligence Cognos 8 Viewer
(AKA Report Viewer). These techniques operate in Cognos 8 Viewer only
and as such do not operate in any other Cognos 8 BI user interfaces such as
Go! Mobile, Go! Dashboards, Query Studio, Analysis Studio, Cognos
Analysis for Excel, Go!Office and so on.
Therefore, the use of the techniques comes with the risk of partial or
complete incompatibility with the possibility of necessitating a partial or
complete change or loss of functionality from release to release. Such risk is
borne entirely by the user of these techniques.
See also the disclaimer of the document referred in 7.1.
2
2 Introduction
This document attempts to consolidate and simplify some basic techniques of
using JavaScript for Cognos Prompts.
The Cognos API for JavaScript prompts has been upgraded from Cognos 8.2 to
Cognos 8.3. A reference can be found in section 7.1below.
The JavaScript code in this document presents by default the Cognos 8.3 version.
Notes have been added where the code is different in Cognos 8.2.
1. Modify the prompts before presenting the prompt page to the user
2. Validate user actions
3. Process the prompts after the user presses Finish
The JavaScript must be placed in one or more HTML items in the prompt page.
The HTML item must be placed after the prompts it refers to.
3
4 Retrieving prompts
To retrieve a prompt, first get the object containing the whole form.
Example: to get the listBox prompt which has been named XYX, the code is:
All other prompt objects can be accessed by adding a named span tag <span>
around the prompt object and accessing the span tag via the getElementById()
function and the prompt object items using the getElementsByTagName() function.
4
5 Common Actions on Prompts
5.1 Modifying the prompts before the prompt page is displayed
To modify a prompt, create a HTML item, and write a script to retrieve the
prompt and set a value for the prompt.
In the following examples, the prompt has the name XYZ.
Create a Value Prompt, and change the “Multi-Select” property to Yes. This
example selects the third value in the list.
5
See also Technote 1342899.
In a page containing some required prompts, the Finish button is enabled only
when the user has selected values for all the required prompts.
The current section shows examples when the prompts are initialized by script. If
all the required prompts are satisfied, then the “Finish” button may be set to enabled, by
calling the function:
canSubmitPrompt()
1. a Text Box Prompt, named ABC, which should be initialized with the string
“Hello”;
2. a Value Prompt of the type ListBox, named DEF, where the first item should be
selected. After that, the “Finish” button should be set to Enabled.
Note 2: canSubmitPrompt() has been introduced in Cognos 8.3. It checks all the
prompts in the page. In Cognos 8.2 the same operation was done by the function
checkData(), applied for each prompt. The function checkData() applies to specific
variables for each prompt. Such a variable has a name as in the following list, followed
by the prompt name:
• checkBoxGroup
• clockDisplay
• intervalControl
• listBox
• pickerControl
• radioGroup
• search
• selectDate
• selectDateTime
6
• selectInterval
• selectTime
• textBox
• timePicker
The same example, now written in Cognos 8.2 will be:
5.2 Running scripts after the user clicks the Finish button
By default, pressing the Finish button will execute the report with the given
prompts. In order to execute additional operations after the user presses the Finish button,
but before the report runs, replace the Finish button with a customized one, as follows:
• Define a JavaScript function to do the expected actions
• Define a new button to launch the function above
• Remove the original Finish button
Example: a prompt page contains a list and a text box. When Finish is pressed, the
text box is filled with the selected option. The prompt page should have:
• the list prompt
• the text prompt
• a HTML item next to the Finish button, containing:
<script>
function fillTextBox() {
var form = getFormWarpRequest();
var list = form._oLstChoicesABC;
var textBox = form._textEditBoxXYZ;
7
}
promptButtonFinish();
}
</script>
8
6 Debugging JavaScript
In the bottom left corner of the IE window, usually there is the IE blue icon and
the text “Done”. Sometimes the icon is the yellow alert sign and the text says “Error on
page”. That means an error has been detected in JavaScript. By double clicking the icon,
an error dialog appears, with the line and text of the error.
7 References
7.1 Upgrading JavaScript Applications to IBM Cognos 8.3/8.4
http://www-01.ibm.com/support/docview.wss?rs=0&uid=swg24021973