You are on page 1of 10

Introduction

Purpose
This technique uses JavaScript to allow a user to pass multiple values to an IBM Cognos 8
Report Studio textbox prompt.
Applicability
The technique in this document should only be used against relational data sources.
The technique identified in this document was validated using:

IBM Cognos 8.4.102.18-0 using the Go Sales (query) package shipped with the samples.

Undocumented and Unsupported Capabilities Used


This technique requires the use of undocumented and unsupported capabilities in IBM Cognos 8.
There may be a risk associated with this technique in that support for these capabilities may
change or be dropped entirely in some future release.
This technique was created as a proof of concept; it does not cover all usage scenarios. This
technique should be thoroughly tested before being used on a live IBM Cognos 8 system.

Back to top
Creating the Base Prompted Report
To create the base report
1. Open IBM Cognos 8 Report Studio against the Go Sales (query) package shipped with
the samples.
2. Select Create a New report or template
3. When prompted, select the List object.
4. From the left hand Insertable Objects pane, drag Go Sales (query)\Sales
(query)\Branch\Branch code into the list.

Figure 1 IBM Cognos 8 Report Studio list report iwth Branch code as a column.

5. Use the View menu to switch to the Prompt page view.


6. Drag the Page object from the left hand Insertable objects pane into the middle Prompt
Pages pane.
Figure 2 IBM Cognos 8 Report Studio displaying Prompt Page 1 within the Page
Explorer.

7. Double-click on the Prompt Page 1 object.


8. From the left hand Insertable Objects pane, locate and drag the Value Prompt object onto
the Prompt page to evoke the Prompt Wizard dialog box.
9. Within the Prompt Wizard dialog box, give the parameter a name. For this example the
name will be BranchCode.
Figure 3 IBM Cognos 8 Report Studio displaying the Value Prompt Prompt Wizard

for the BranchCode parameter.

10. Click the Next button.


11. Within the Create Filter section of the Prompt Wizard dialog box, use the ellipses to add
the [Sales (query)].[Branch].[Branch code] package item.
12. Use the drop down box to change the operator from = to in.
Figure 4 IBM Cognos 8 Report Studio Prompt Wizard for the value prompt

displaying the in operator.

13. Click the Next button.


14. Click the Finish button to return to the Prompt Page screen.
15. From the left hand Insertable Objects pane, locate and drag Text box Prompt to the left of
the previously added value prompt.
16. Within the Prompt Wizard dialog box, give the parameter a name. For this example the
name will be BranchCodeTB.
17. Click the Finish Button to return to the Prompt page.
Figure 5 IBM Cognos 8 Report Studio displaying the Prompt page with the textbox

and value prompt side by side.

18. Within the Prompt page, highlight the Text box prompt by clicking on it.
19. Within the bottom left Properties pane, add a name of id2 to the Miscellaneous\Name
attribute.
Figure 6 IBM Cognos 8 Report Studio Prompt Page showing the textbox prompt

highlighted.

20. Within the Prompt page, highlight the Value prompt by clicking on it.
21. Within the bottom left Properties pane, add a name of id3 to the Miscellaneous\Name
attribute.

Back to top
Replacing the Finish Button using JavaScript
An easy way to validate prompt data before submitting it to the report is to replace the generated
Finish button with a JavaScript one. To do this:
1. At the bottom of the Prompt page, highlight the Finish button and delete it.
2. From the left hand Insertable objects pane, locate the HTML object.
3. Drag the HTML object to the same location of the previously deleted Finish button.
Figure 7 IBM Cognos 8 Report Studio Prompt page showing the HTML toolbox

item that has been used to replace the Finish button.

4. Double click the previously added HTML Item and add the following code.
<input type="BUTTON" class="clsPromptButton" onClick="SplitText()" value="
Finish ">

5.
6. Click the OK button to commit the HTML code.

Back to top
Adding the JavaScript to Parse the Text Prompt Values
1. From the left hand Insertable objects pane, locate the HTML object.
2. Drag the HTML object to the right of the Value Prompt.
Figure 8 IBM Cognos 8 Report Studio Prompt page with an HTML item next to the

value prompt.

3. Double-Click the HTML Item and add the following code.


<script language="javascript">
var fW = (typeof getFormWarpRequest == "function" ?
getFormWarpRequest() : document.forms["formWarpRequest"]);
if ( !fW || fW == undefined) { fW = ( formWarpRequest_THIS_ ?
formWarpRequest_THIS_ : formWarpRequest_NS_ );}
var var1=fW._textEditBoxid2; //The visible text prompt
var var2=fW._oLstChoicesid3; //The hidden multi-select value prompt
function SplitText()
{
if ((var1.value=='')|| (var1.value==null)) //Check to see if values were
entered
{
alert("No values were entered! Please enter some values.");
}
else
{
var text_array=var1.value.split(" ");
// Break out the value entered in the text prompt using the space as a
separator
var numberofsplits=0;
while (numberofsplits < text_array.length)
{
for (var i=0;i < var2.length; i++)
//Go through every value in the value prompt

if(var2[i].value==text_array[numberofsplits])
//if the value from the text prompt is
//present in the value prompt select it
{
var2[i].selected=true;
}

}
numberofsplits++;
}
promptButtonFinish();
}
}
</script>

4. Click the OK button to commit the HTML code.


5. Run the report, and type the following string (without the quotes) into the text box
prompt.
"6 19 21"
6. Click the Finish button to submit the entered text prompt values. Notice that the values
entered in the text box are used to select the values in the Value prompt. The values
selected within the value prompt are then submitted to the report.
7. Now all that is left to do is to hide the Value prompt. Close the IBM Cognos Viewer and
return to IBM Cognos 8 Report Studio.
8. Within the Prompt Page, highlight the Value prompt by clicking on it.
9. Within the bottom left hand Properties pane, change the Positioning\Visible attribute to
No.
Figure 9 IBM Cognos 8 Report Studio Prompt Page with the value prompt

highlighted.

10. Re-run the report, and type the following string (without the quotes) into the text box.
"6 19 21"
11. Click the Finish button.
Figure 10 IBM Cognos 8 Report Viewer showing hte resultant list in HTML format.

You might also like