Vous êtes sur la page 1sur 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

Using JavaScript to Pass Multiple Values to a Textbox Prompt within IBM Cognos 8 Report Studio Copyright and Trademarks Licensed Materials - Property of IBM. Copyright IBM Corp. 2010

IBM, the IBM logo, and Cognos are trademarks or registered trademarks of International Business Machines Corp., registered in many jurisdictions worldwide. Other product and service names might be trademarks of IBM or other companies. A current 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 document is accurate and complete, some typographical errors or technical inaccuracies may exist. IBM does not accept responsibility for any kind of loss resulting from the use of information contained in this document. The information contained in this document 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 cscogpp@ca.ibm.com. Microsoft, Windows, Windows NT, and the Windows logo are trademarks of Microsoft 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

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

INTRODUCTION.........................................................................................................4 PURPOSE..............................................................................................................................4 APPLICABILITY......................................................................................................................... 4 UNDOCUMENTED 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

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

1 Introduction
1.1 Purpose This technique uses JavaScript to allow a user to pass multiple values to an IBM Cognos 8 Report Studio textbox prompt. 1.2 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. 1.3 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.

2 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.

Business Analytics

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

Figure 1 IBM Cognos 8 Report Studio list report with 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.

Business Analytics

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

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.

Business Analytics

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

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.

Business Analytics

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

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.

Business Analytics

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

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.

3 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.

Business Analytics

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

10

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. Click the OK button to commit the HTML code.

6. 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.

Business Analytics

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

11

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)) values were entered { alert("No values were entered! } Please enter some values."); //Check to see if

Business Analytics

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

12

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.

Business Analytics

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

13

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 the resultant list in HTML format.

Business Analytics

Vous aimerez peut-être aussi