Using Javascript to Pass Multiple Values to a Textbox Prompt Within IBM Cognos 8 Report Studio

13
Tip or Technique Using JavaScript to Pass Multiple Values to a Textbox Prompt within IBM Cognos 8 Report Studio Product(s): IBM Cognos 8 Area of Interest: Reporting

Transcript of Using Javascript to Pass Multiple Values to a Textbox Prompt Within IBM Cognos 8 Report Studio

Page 1: Using Javascript to Pass Multiple Values to a Textbox Prompt Within IBM Cognos 8 Report Studio

Tip or Technique

Using JavaScript to Pass Multiple Values to a Textbox Prompt within IBM Cognos 8 Report

Studio

Product(s): IBM Cognos 8

Area of Interest: Reporting

Page 2: Using Javascript to Pass Multiple Values to a Textbox Prompt Within IBM Cognos 8 Report Studio

Using JavaScript to Pass Multiple Values to a Textbox Prompt withinIBM Cognos 8 Report Studio

2

Copyright and Trademarks Licensed Materials - Property of IBM.

© Copyright IBM Corp. 2010

IBM, the IBM logo, and Cognos are trademarks or registered trademarks ofInternational Business Machines Corp., registered in many jurisdictions worldwide.Other product and service names might be trademarks of IBM or other companies. Acurrent list of IBM trademarks is available on the Web at http://www.ibm.com/legal/copytrade.shtml

While every attempt has been made to ensure that the information in this documentis accurate and complete, some typographical errors or technical inaccuracies mayexist. IBM does not accept responsibility for any kind of loss resulting from the useof information contained in this document. The information contained in thisdocument is subject to change without notice.This document is maintained by the Best Practices, Product and Technology team.You can send comments, suggestions, and additions to [email protected].

Microsoft, Windows, Windows NT, and the Windows logo are trademarks ofMicrosoft Corporation in the United States, other countries, or both.

Java and all Java-based trademarks and logos are trademarks of Sun Microsystems,Inc. in the United States, other countries, or both.

Business Analytics

Page 3: Using Javascript to Pass Multiple Values to a Textbox Prompt Within IBM Cognos 8 Report Studio

Using JavaScript to Pass Multiple Values to a Textbox Prompt withinIBM Cognos 8 Report Studio

3

Contents

INTRODUCTION ......................................................................................................... 4

PURPOSE..............................................................................................................................4APPLICABILITY.........................................................................................................................4UNDOCUMENTED AND UNSUPPORTED CAPABILITIES USED..........................................................................4

CREATING THE BASE PROMPTED REPORT ................................................................ 4

REPLACING THE FINISH BUTTON USING JAVASCRIPT ............................................. 9

ADDING THE JAVASCRIPT TO PARSE THE TEXT PROMPT VALUES .......................... 10

Business Analytics

Page 4: Using Javascript to Pass Multiple Values to a Textbox Prompt Within IBM Cognos 8 Report Studio

Using JavaScript to Pass Multiple Values to a Textbox Prompt withinIBM Cognos 8 Report Studio

4

1 Introduction

1.1 Purpose

This technique uses JavaScript to allow a user to pass multiple values to anIBM Cognos 8 Report Studio textbox prompt.

1.2 Applicability

The technique in this document should only be used against relational datasources.The technique identified in this document was validated using:

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

1.3 Undocumented and Unsupported Capabilities Used

This technique requires the use of undocumented and unsupportedcapabilities in IBM Cognos 8. There may be a risk associated with thistechnique in that support for these capabilities may change or be droppedentirely in some future release.

This technique was created as a proof of concept; it does not cover all usagescenarios. This technique should be thoroughly tested before being used ona live IBM Cognos 8 system.

2 Creating the Base Prompted Report

To create the base report1. Open IBM Cognos 8 Report Studio against the Go Sales (query)

package shipped with the samples.2. Select Create a New report or template3. 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.

Business Analytics

Page 5: Using Javascript to Pass Multiple Values to a Textbox Prompt Within IBM Cognos 8 Report Studio

Using JavaScript to Pass Multiple Values to a Textbox Prompt withinIBM Cognos 8 Report Studio

5

Figure 1 IBM Cognos 8 Report Studio list report with Branch code as acolumn.

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 withinthe 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 Wizarddialog box.

9. Within the Prompt Wizard dialog box, give the parameter a name.For this example the name will be BranchCode.

Business Analytics

Page 6: Using Javascript to Pass Multiple Values to a Textbox Prompt Within IBM Cognos 8 Report Studio

Using JavaScript to Pass Multiple Values to a Textbox Prompt withinIBM Cognos 8 Report Studio

6

Figure 3 IBM Cognos 8 Report Studio displaying the Value PromptPrompt 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.

Business Analytics

Page 7: Using Javascript to Pass Multiple Values to a Textbox Prompt Within IBM Cognos 8 Report Studio

Using JavaScript to Pass Multiple Values to a Textbox Prompt withinIBM Cognos 8 Report Studio

7

Figure 4 IBM Cognos 8 Report Studio Prompt Wizard for the value prompt displayingthe 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.

Business Analytics

Page 8: Using Javascript to Pass Multiple Values to a Textbox Prompt Within IBM Cognos 8 Report Studio

Using JavaScript to Pass Multiple Values to a Textbox Prompt withinIBM Cognos 8 Report Studio

8

Figure 5 IBM Cognos 8 Report Studio displaying the Prompt page withthe textbox and value prompt side by side.

18. Within the Prompt page, highlight the Text box prompt by clicking onit.

19. Within the bottom left Properties pane, add a name of id2 to theMiscellaneous\Name attribute.

Business Analytics

Page 9: Using Javascript to Pass Multiple Values to a Textbox Prompt Within IBM Cognos 8 Report Studio

Using JavaScript to Pass Multiple Values to a Textbox Prompt withinIBM Cognos 8 Report Studio

9

Figure 6 IBM Cognos 8 Report Studio Prompt Page showing thetextbox 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.

3 Replacing the Finish Button using JavaScript

An easy way to validate prompt data before submitting it to the report isto replace the generated Finish button with a JavaScript one. To do this:

1. At the bottom of the Prompt page, highlight the Finish button anddelete 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.

Business Analytics

Page 10: Using Javascript to Pass Multiple Values to a Textbox Prompt Within IBM Cognos 8 Report Studio

Using JavaScript to Pass Multiple Values to a Textbox Prompt withinIBM Cognos 8 Report Studio

10

Figure 7 IBM Cognos 8 Report Studio Prompt page showing the HTMLtoolbox item that has been used to replace the Finish button.

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

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

6. Adding the JavaScript to Parse the Text PromptValues

1. From the left hand Insertable objects pane, locate the HTML object.2. Drag the HTML object to the right of the Value Prompt.

Business Analytics

Page 11: Using Javascript to Pass Multiple Values to a Textbox Prompt Within IBM Cognos 8 Report Studio

Using JavaScript to Pass Multiple Values to a Textbox Prompt withinIBM Cognos 8 Report Studio

11

Figure 8 IBM Cognos 8 Report Studio Prompt page with an HTML item next to thevalue 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 promptvar var2=fW._oLstChoicesid3; //The hidden multi-select valueprompt

function SplitText() { if ((var1.value=='')|| (var1.value==null)) //Check to see ifvalues were entered{alert("No values were entered! Please enter some values.");}

Business Analytics

Page 12: Using Javascript to Pass Multiple Values to a Textbox Prompt Within IBM Cognos 8 Report Studio

Using JavaScript to Pass Multiple Values to a Textbox Prompt withinIBM Cognos 8 Report Studio

12

else{var text_array=var1.value.split(" "); // Break out the valueentered in the text prompt using the space as a separatorvar 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 thevalue from the text prompt is present in the value promptselect 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 thevalues in the Value prompt. The values selected within the valueprompt are then submitted to the report.

7. Now all that is left to do is to hide the Value prompt. Close the IBMCognos 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.

Business Analytics

Page 13: Using Javascript to Pass Multiple Values to a Textbox Prompt Within IBM Cognos 8 Report Studio

Using JavaScript to Pass Multiple Values to a Textbox Prompt withinIBM Cognos 8 Report Studio

13

Figure 9 IBM Cognos 8 Report Studio Prompt Page with the valueprompt 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 the resultant list inHTML format.

Business Analytics