9

Click here to load reader

BI-Restrict Tree Prompt Selection With JavaScript

Embed Size (px)

Citation preview

Page 1: BI-Restrict Tree Prompt Selection With JavaScript

IBM Cognos BI - Restrict Tree PromptSelection with JavaScript

Nature of Document: Tip or Technique

Product(s): IBM Cognos BI Report Studio

Area of Interest: Report Design

Business Analytics

Page 2: BI-Restrict Tree Prompt Selection With JavaScript

IBM Cognos BI - Restrict Tree Prompt Selection with JavaScript

Copyright and Trademarks Licensed Materials - Property of IBM.

© Copyright IBM Corp. 2010

IBM, the IBM logo, and Cognos are trademarks or registered trademarks of InternationalBusiness Machines Corp., registered in many jurisdictions worldwide. Other product andservice names might be trademarks of IBM or other companies. A current list of IBMtrademarks 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 isaccurate and complete, some typographical errors or technical inaccuracies may exist. IBMdoes not accept responsibility for any kind of loss resulting from the use of informationcontained in this document. The information contained in this document is subject to changewithout notice.This document is maintained by the Best Practices, Product and Technology team. You cansend comments, suggestions, and additions to [email protected].

Business Analytics

2

Page 3: BI-Restrict Tree Prompt Selection With JavaScript

IBM Cognos BI - Restrict Tree Prompt Selection with JavaScript

Table of Contents1 Introduction .................................................................................................................. 4

1.1 Purpose ........................................................................................................................ 4 1.2 Applicability .................................................................................................................. 4 1.3 Assumptions ................................................................................................................. 4 1.4 Exclusions and Exceptions .............................................................................................. 4

2 Overview ...................................................................................................................... 4

3 Restrict Tree Prompt Selection with JavaScript (Step-by-Step Instructions) ....................... 5

Business Analytics

3

Page 4: BI-Restrict Tree Prompt Selection With JavaScript

IBM Cognos BI - Restrict Tree Prompt Selection with JavaScript

1 Introduction

1.1 Purpose

This document describes a technique for report developers that wish to utilize a Tree Prompt butrequire that the value submitted be restricted to a designated level within a hierarchy.

1.2 Applicability

This technique applies to IBM Cognos 8.3 SP3+, 8.4, 8.4.1, and 10.1 using the Great Outdoor Sales(cube) sample shipped with the product.

1.3 Assumptions

This document assumes experience developing dimensional reports in IBM Cognos Report Studio.

1.4 Exclusions and Exceptions

This technique applies to single-select tree prompts only.

This technique requires the use of undocumented and unsupported capabilities in IBM Cognos BI.There may be a risk associated with this technique in that support for these capabilities may changeor be dropped entirely in some future release.

This technique was created as a proof of concept and does not cover all usage scenarios. Thistechnique should be thoroughly tested before being used on a live IBM Cognos BI system.

2 OverviewTree Prompts are used in dimensional reporting and allow the user to submit a value from anydisplayed level within a dimension's hierarchy. It is an easy to use graphical interface that allowsusers to quickly get to the value or values they are concerned with when filtering their reports.

The alternative to tree prompts would be a series of cascading value prompts, which may not be asdesirable as the use of a single Tree Prompt.

In some cases, a tree prompt may be desirable for a value selection, but only one of the levels isrequired to filter the report. For example, a report has a filter on the month level. A tree prompt canbe used to allow the user to quickly navigate through the years and quarters to get to the desiredmonth. In these cases, the report developer may want to restrict the value submitted through a TreePrompt to a specific level in the dimension's hierarchy. In this case, the Month level.

Business Analytics

4

Page 5: BI-Restrict Tree Prompt Selection With JavaScript

IBM Cognos BI - Restrict Tree Prompt Selection with JavaScript

3 Restrict Tree Prompt Selection with JavaScript(Step-by-Step Instructions)

The following will show an example of implementing a tree prompt that uses JavaScript to restrict amember selection at the month level of the Years dimension.

The report in this example is a simple crosstab report with Revenue as the measure, Product lines onthe rows, and a query calculation called Month on the columns that prompts for a specific month fromthe Years hierarchy of the Years dimension.

The Month calculation has the following expression.

[great_outdoors_sales_en].[Years].[Years].[Month]->?Month?

To enhance this report with a tree prompt that restricts user selection to the Month level, use thefollowing steps.

1. Add a prompt page to the report.

2. Add a Tree Prompt to the prompt page.

3. In the Prompt Wizard dialog, select Use existing parameter, and then select Month from thedrop down list.

Business Analytics

5

Page 6: BI-Restrict Tree Prompt Selection With JavaScript

IBM Cognos BI - Restrict Tree Prompt Selection with JavaScript

4. Click Next, click the ellipsis (...) beside Values to use, and then select the Years hierarchyunder the Years dimension. This allows the Tree prompt to display all members of thehierarchy.

5. Click OK, and then click Finish.

6. Select the Tree prompt on the prompt page, and then in the Properties pane, in the Nameproperty under Miscellaneous, enter MyTreePrompt. This name will be referenced in theJavaScript code you will use in an upcoming step.

7. Add an HTML Item to prompt page.

Business Analytics

6

Page 7: BI-Restrict Tree Prompt Selection With JavaScript

IBM Cognos BI - Restrict Tree Prompt Selection with JavaScript

8. Double-click the HTML item and add the following code to it.

<script> function getSelectedTreeLevel() { if (window.treeMyTreePrompt) { var selectedTreeNode = window.treeMyTreePrompt.getLastSelectedNode(); if (selectedTreeNode!=null) { var selectedLevel = window.treeMyTreePrompt.getLastSelectedNode().getLevel(); if (selectedLevel != 4) //Set level number that should be selectedfor selectedLevel { alert("Select a Month for this Report"); //alert when wronglevel is selected }else { promptButtonFinish(); } }else { alert("You must make a selection"); } //alert if no item has beenselected }else { alert("treeMyTreePrompt is undefined"); } //alert when no tree promptwith that name has been found} </script>

9. Click OK.

10. On the prompt page, delete the existing Finish button and in its place add another HTMLitem.

11. Double-click the HTML item and add the following code.

<input type="button" class="bp" value="Finish" onClick="getSelectedTreeLevel()"/>

Business Analytics

7

Page 8: BI-Restrict Tree Prompt Selection With JavaScript

IBM Cognos BI - Restrict Tree Prompt Selection with JavaScript

12. Run the report, and then click the Finish button.

Business Analytics

8

Page 9: BI-Restrict Tree Prompt Selection With JavaScript

IBM Cognos BI - Restrict Tree Prompt Selection with JavaScript

13. Click OK, select a member from the Quarter level, and then click Finish.

14. Click OK, select a member from the Month level, and then click Finish.

The report runs and filters the report based on the tree prompt selection.

Business Analytics

9