auto cascadingprompts without page refresh in ibm cognosreport studio

11
© Copyright IBM Corporation 2011, 2012 Trademarks IBM Cognos Proven Practices: Auto Cascading Prompts without Page Refresh in IBM Cognos Report Studio Page 1 of 11 IBM Cognos Proven Practices: Auto Cascading Prompts without Page Refresh in IBM Cognos Report Studio Nature of Document: Tip or Technique; Product(s): IBM Cognos Report Studio; Area of Interest: Reporting Amit Shivde Systems Analyst Cognizant Technology Solutions Smit Modi Senior System Analyst Cognizant Technology Solutions Skill Level: Advanced Date: 22 Aug 2011 (Updated 10 Dec 2012) This document provides technique to implement auto-cascading of Value prompts without having to do a page refresh. View more content in this series Introduction Purpose This document provides technique to implement auto-cascading of Value prompts without having to do a page refresh. Applicability This technique has been tested in the IBM Cognos 8.2, IBM Cognos 8.4.0, IBM Cognos 8.4.1 and IBM Cognos 10.1 Report Studio versions. This technique has been implemented using JavaScript.

Upload: clrhoades

Post on 24-Oct-2015

207 views

Category:

Documents


5 download

DESCRIPTION

cognos

TRANSCRIPT

Page 1: Auto CascadingPrompts Without Page Refresh in IBM CognosReport Studio

© Copyright IBM Corporation 2011, 2012 TrademarksIBM Cognos Proven Practices: Auto Cascading Promptswithout Page Refresh in IBM Cognos Report Studio

Page 1 of 11

IBM Cognos Proven Practices: Auto CascadingPrompts without Page Refresh in IBM CognosReport StudioNature of Document: Tip or Technique; Product(s): IBMCognos Report Studio; Area of Interest: Reporting

Amit ShivdeSystems AnalystCognizant Technology Solutions

Smit ModiSenior System AnalystCognizant Technology Solutions

Skill Level: Advanced

Date: 22 Aug 2011(Updated 10 Dec 2012)

This document provides technique to implement auto-cascading of Value promptswithout having to do a page refresh.

View more content in this series

Introduction

Purpose

This document provides technique to implement auto-cascading of Value promptswithout having to do a page refresh.

Applicability

This technique has been tested in the IBM Cognos 8.2, IBM Cognos 8.4.0, IBMCognos 8.4.1 and IBM Cognos 10.1 Report Studio versions. This technique has beenimplemented using JavaScript.

Page 2: Auto CascadingPrompts Without Page Refresh in IBM CognosReport Studio

developerWorks® ibm.com/developerWorks/

IBM Cognos Proven Practices: Auto Cascading Promptswithout Page Refresh in IBM Cognos Report Studio

Page 2 of 11

Exclusions and ExceptionsThis technique works perfectly in Internet Explorer version 5.0 and above. This willnot work with Firefox.

This technique requires the use of undocumented and unsupported capabilities inIBM Cognos BI. There may be a risk associated with this technique in that support forthese capabilities may change or be dropped entirely in some future release.

Auto-cascading promptCascading of prompt values are typically required for reporting applications in orderto limit the data scope and reduce chances of getting no data on report output. NativeIBM Cognos functionality does provide capability to auto-cascade on a ‘single selectvalue prompt’ or with ‘Re-prompt button on multi-select value prompt’ where theentire prompt selection page would refresh for each prompt selection. Hence, if thenumbers of prompts are significant, this approach of entire page refresh becomesvery time consuming and annoying for end users.

Steps to implement auto cascading without page refresh:1. Add the required value prompts on the prompt page which are needed for the

cascaded. In the current example, Product Line, Product Type and ProductName prompts have been added. Product Type is cascaded on Product Lineand Product Name is cascaded on Product Line and Product Type. Each ofthese prompt boxes has its own query.Report Studio prompt page with Product Line, Product Type and ProductName

2. Give names to each of these prompts. In this example, Prompt Names will startwith "PN_". Giving unique name to each of the prompt is essential to accessthese prompts using JavaScript. Product Line prompt has been named asPN_ProductLine, Product Type named as PN_ProductType and Product Namenamed as PN_Product. The names are entered under Miscellaneous → Namein the Value Prompt properties.

3. Create a new query, which will include the concatenation of values for all promptquery items. In this example, Q_Prompt query has been created with a newdata item expression called “Concat String” which will concate all three prompt

Page 3: Auto CascadingPrompts Without Page Refresh in IBM CognosReport Studio

ibm.com/developerWorks/ developerWorks®

IBM Cognos Proven Practices: Auto Cascading Promptswithout Page Refresh in IBM Cognos Report Studio

Page 3 of 11

values as string. Please make sure while concatenating use different identifierbetween each value.The expression is the following:'!' || [gosales_goretailers].[Products].[Product line] || '~'||[gosales_goretailers].[Products].[Product type] || '#' ||[gosales_goretailers].[Products].[Product name] || '^'

Data Item Expression window

Note: In case of different use and display value, display value should be usedfor concatenation.

4. On the prompt page, insert one HTML item after the prompts, and in thisexample, call it 'fW Script' then include the following code:<script>var fW = (typeof getFormWarpRequest == "function" ?getFormWarpRequest() : document.forms["formWarpRequest"]);if ( !fW || fW == undefined) { fW = ( formWarpRequest_THIS_ ?formWarpRequest_THIS_ : formWarpRequest_NS_ );}</script>

5. On the prompt page, insert another HTML item next to first HTML item. Call it‘GetAllPromptNames’ then insert following code:<script>//------------------------------------get All Prompt Names----------------------function getAllPromptNames(){

var aPromptNames = new Array();

for (var i in window) {if ( (""+i).match(/^listBox/) ) {var sName = i.replace( /^listBox/, "" );

Page 4: Auto CascadingPrompts Without Page Refresh in IBM CognosReport Studio

developerWorks® ibm.com/developerWorks/

IBM Cognos Proven Practices: Auto Cascading Promptswithout Page Refresh in IBM Cognos Report Studio

Page 4 of 11

aPromptNames.push (sName);}else if ( (""+i).match(/^radioList/) ){

var sName = i;aPromptNames.push (sName);}else if ( (""+i).match(/^checkBoxList/) ){

var sName = i;aPromptNames.push (sName);}}return aPromptNames;//-----------------------------------to avoid Memory Leak---- i=null; sName=null

}//------------------------------------get All Prompt Names----------------------

// hiding select All/deselect Allfor(j=0;j<document.links.length;j++){y=document.links[j];if (y.id.indexOf("SELECT") != -1) document.getElementById(y.id).style.display='None';}</script>

6. On the prompt page, insert third HTML item next to previously inserted HTMLitems and insert following code in that:<script>String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g,"");} fW._oLstChoicesPN_ProductLine.onchange = function () {cascadePrompts("ProductLine","ProductType,Product")}; fW._oLstChoicesPN_ProductType.onchange = function () {cascadePrompts("ProductType","Product")};

//Check if the prompts being cascaded are present// on page or removed as per report requirementfunction validatePrompts(removearr){promptsonpage=getAllPromptNames(); var flag ; newarr = new Array(); var i=0; for(var j =0 ; j < removearr.length ; j++ ) { flag = false; for (var jj =0 ; jj < promptsonpage.length ; jj++ ){

if(("PN_"+removearr[j])==promptsonpage[jj]) { flag=true; break; } } if(flag==true ) { newarr[i]=removearr[j]; i++; } } return newarr;}

Page 5: Auto CascadingPrompts Without Page Refresh in IBM CognosReport Studio

ibm.com/developerWorks/ developerWorks®

IBM Cognos Proven Practices: Auto Cascading Promptswithout Page Refresh in IBM Cognos Report Studio

Page 5 of 11

//calls all the functions required for cascadeing // prompt: Listprompt on which has the values to filter the child prompts //remove: Child prompts on which the cascading is supposed to be performedfunction cascadePrompts(prompt,remove){ removearr = new Array(); removearr = remove.split(",");

newarray=validatePrompts(removearr);emptyList(newarray);createList(prompt,newarray);}

//Empty child prompts before you insert new filtered valuesfunction emptyList(arr){ for (var jj =0 ; jj < arr.length ; jj++ ){ fW["_oLstChoicesPN_"+arr[jj]].selectedIndex = -1; fW["_oLstChoicesPN_"+arr[jj]].length = 0; }//------------------to avoid memory leak----- arr=null;}

//creates the filter arrayfunction createList(prompt,newarr) { var len2 = fW["_oLstChoicesPN_"+prompt].length; arrfilter = new Array(); var idx = 0; for (var j = 0 ; j < len2; j++){ if (fW["_oLstChoicesPN_"+prompt][j].selected == true){ arrfilter[idx] = fW["_oLstChoicesPN_"+prompt][j].value; idx++; } } for (var jj =0 ; jj < newarr.length ; jj++ ) { createListFilter(prompt,newarr[jj],arrfilter); }

//------------------to avoid memory leak----- arrfilter=null; newarr = null;}

function createParentFilter(prompt){var len2 = fW["_oLstChoicesPN_" + prompt].length; var filter = new Array(); var idx = 0;

for (var j = 0 ; j < len2; j++){ if (fW["_oLstChoicesPN_"+prompt][j].selected == true){

filter[idx] = fW["_oLstChoicesPN_"+ prompt][j].value; idx++; } } return filter;

}function checkParentFilter(string,fltr,flg){

for(var k=0;k<fltr.length;k++) { if(fltr[k]!="All" && flg){ if(string.match(fltr[k]))

Page 6: Auto CascadingPrompts Without Page Refresh in IBM CognosReport Studio

developerWorks® ibm.com/developerWorks/

IBM Cognos Proven Practices: Auto Cascading Promptswithout Page Refresh in IBM Cognos Report Studio

Page 6 of 11

{ return true;

}

} else { return flg;}

}if(fltr.length==0) {return true;} flg=false; return flg;}

function createListFilter(filterlevel,filtervalues,filter){var parFiltersStr= "ProductLine,ProductType"; parentarr = new Array(); parentarr = parFiltersStr.split(","); newParentArr = validatePrompts(parentarr); parentFilterStr=newParentArr.join();

ProductLinefilter= new Array(); if(parentFilterStr.match("ProductLine")){ ProductLinefilter=createParentFilter("ProductLine"); } else{ ProductLinefilter[0]="All" }//-------------------------Product Line filters---

ProductTypefilter = new Array(); if(parentFilterStr.match("ProductType")){ ProductTypefilter =createParentFilter("ProductType"); } else{ ProductTypefilter[0]="All" }//-------------------------Product Type filters---

var fd;var sd;var td;var frd;var tdidx = 0;var fdidx = 0;var sdidx;var frdidx;arr = new Array ();if (filterlevel == "ProductLine"){ fd = "!"; sd = "~"; }

if (filterlevel == "ProductType"){ fd = "~"; sd = "#"; }

if (filterlevel == "Product"){ fd = "#"; sd = "^"; } // ----------------------------------filter Values------------------------------

if (filtervalues == "ProductLine"){ td = "!"; frd = "~"; }

if (filtervalues == "ProductType"){

Page 7: Auto CascadingPrompts Without Page Refresh in IBM CognosReport Studio

ibm.com/developerWorks/ developerWorks®

IBM Cognos Proven Practices: Auto Cascading Promptswithout Page Refresh in IBM Cognos Report Studio

Page 7 of 11

td = "~"; frd = "#"; } if (filtervalues == "Product"){ td = "#"; frd = "^"; }

var len = fW._oLstChoicesPN_ConcatString.length;

for (var idx= 0 ; idx < filter.length ; idx++){ for(var i = 0 ; i < len ; i++){

var string2 = fW._oLstChoicesPN_ConcatString[i].value; fdidx = string2.indexOf(fd); sdidx = string2.indexOf(sd); tdidx = string2.indexOf(td); frdidx = string2.indexOf(frd); var string3 = string2.substring(fdidx+1,sdidx); if (filter[idx] != "All"){ if ( string3.trim() == filter[idx].trim() ){ var flag=true; flag=checkParentFilter(string2,ProductLinefilter,flag); flag=checkParentFilter(string2,ProductTypefilter,flag); if(flag) {

arr[i] = string2.substring(tdidx+1,frdidx); } } } else { var flag=true; flag=checkParentFilter(string2,ProductLinefilter,flag); flag=checkParentFilter(string2,ProductTypefilter,flag); if(flag) { arr[i] = string2.substring(tdidx+1,frdidx); } } } }

arr = uniqueVal(arr); filtervalues = "_oLstChoicesPN_"+filtervalues; for (var j=0 ; j < arr.length ; j++){ if (arr[j] != undefined && arr[j] !=null && arr[j] != ""){ var elOptNew = document.createElement('option'); elOptNew.text = arr[j]; elOptNew.value = arr[j]; fW[filtervalues].add(elOptNew); } } //------------------to avoid memory leak----- arr=null; regionfilter=null; countryfilter=null; filter=null; string2=null;}function uniqueVal(oldarr){oldarr.sort();j=0;newarr= new Array()for(var i=0;i<oldarr.length;i++){newarr[j]=oldarr[i];j++;if((i>0)&&(oldarr[i]==oldarr[i-1])){newarr.pop();j--}

Page 8: Auto CascadingPrompts Without Page Refresh in IBM CognosReport Studio

developerWorks® ibm.com/developerWorks/

IBM Cognos Proven Practices: Auto Cascading Promptswithout Page Refresh in IBM Cognos Report Studio

Page 8 of 11

}return newarr;}</script>

In the sample code, this HTML item is referred as ‘Cascading Prompts’. Thiscode includes logic for the auto cascading of the prompt values without pagerefresh.

Report Studio Prompt page showing the scrip objects below the ProductLine, Product Type and Product Name prompt

7. Now go to Page One in the Report Pages and create a column chart showingorder method and production cost. Create three filter items that will filteron Product Line, Product Type and Product Name if not done already. ForExample:

• [Sales (query)].[Product].[Product line] in ?P_ProductLine?• [Sales (query)].[Product].[Product type] in ?P_ProductType?• [Sales (query)].[Product].[Product name] in ?P_Product?

Note: Make sure that the parameter names in the filter expressions, matchesthe parameter names on the prompt page.

8. Save this report .

Steps to expand auto cascading to more value prompts

1. In the ‘Cascading Prompts’ HTML item code, needs add ‘onchange’ event for anew prompt and need to pass the child prompt names for that prompt.

2. Modification in the parFiltersStr variable needs to done as per the hierarchy ofthe prompts. Also new arrays for the same needs to be created.

3. Modification in query (In the current example Q_Prompt) for the hidden promptusing which cascading functionality is working needs to be done. A Columnneeds to be added in the query with the delimiters. And the changes in the

Page 9: Auto CascadingPrompts Without Page Refresh in IBM CognosReport Studio

ibm.com/developerWorks/ developerWorks®

IBM Cognos Proven Practices: Auto Cascading Promptswithout Page Refresh in IBM Cognos Report Studio

Page 9 of 11

if conditions for filterlevel and filtervalues as per the delimiters defined in thequery needs to be modified/added.

4. Condition to check parent prompt values needs to be added as added in thecurrent code "flag=checkParentFilter(string2,ProductLinefilter,flag);” .

Impact on User Productivity

Here is an example of how this technique could save time. A company with a Cognos8.4.0 implementation with 200+ operational reports in which this method has beenimplemented with a user base of 700+ active users globally. With the out of thebox functionality of Cognos 8, there is a increasing chances of getting ‘No DataFound’ results more often, impacting on the user productivity due to multiple times re-running report to get more data or waiting for prompts to retrieve the data to show theconsumer.

With this method, it saved an average of about a minute in execution time perreport per user. So, if each user ran all the reports 5 times a day (700*5)(Numberof users*time saved in execution of reports), there could be a 3500 minute per dayincrease of productivity.

Now this is just an example, results may very depending on number of prompt,amount of data returned, amount of users, etc.

Page 10: Auto CascadingPrompts Without Page Refresh in IBM CognosReport Studio

developerWorks® ibm.com/developerWorks/

IBM Cognos Proven Practices: Auto Cascading Promptswithout Page Refresh in IBM Cognos Report Studio

Page 10 of 11

Downloads

Description Name Size Downloadmethod

Auto_Cascading_Report_specs.zip 10KB FTP

Information about download methods

Page 11: Auto CascadingPrompts Without Page Refresh in IBM CognosReport Studio

ibm.com/developerWorks/ developerWorks®

IBM Cognos Proven Practices: Auto Cascading Promptswithout Page Refresh in IBM Cognos Report Studio

Page 11 of 11

About the authors

Amit Shivde

Amit Shivde is an systems analyst with Cognizant Technology Solutions.He has been working in Data Warehousing projects for past 3.5 years.He has worked extensively with Cognos tool for complex reporting andproviding solutions to clients as per their business requirements.

Smit Modi

Smit Modi is a solution-focused technology specialist with over 4 yearsof experience in IBM Cognos BI Suite. He is very competent in theapplication of BI strategies and techniques to practical situations. Smithas worked extensively in the Cognos BI product suite with relationaldata sources. He has worked in different business units includingBanking, Financial Services and Pharma.

© Copyright IBM Corporation 2011, 2012(www.ibm.com/legal/copytrade.shtml)Trademarks(www.ibm.com/developerworks/ibm/trademarks/)