How to Enhance Text Box Prompts in IBM Cognos 8 with On-The-Fly Validation


One of the issues with using text box prompts is the possibility of receiving incorrect, misspelled, or non-existent entries. This allows the report to run and return unexpected data. Recognizing this, a user would have to return to the prompt page to re-enter values into the text box prompt. Wouldn’t it be nice if there was a way to automatically validate entries against some specified rules while remaining on the prompt page?
In this example we’ll show you how to validate user entry of 3 digit numeric codes with a 5 code maximum.
You can change the code according to your own requirements.
This method will display error messages to the user when their entries do not conform to these rules.

Here is how:

1) Create a new IBM Cognos 8 Report Studio report.
2) Add a prompt page to your report.
3) From the Toolbox menu, drag a Text Box Prompt object onto your prompt page. The “Prompt Wizard” opens. Leave the default parameter name and click Finish.
4) Select the prompt object and assign it a name by navigating to the Properties area (bottom left of the page) and entering a value in the Name property, which can be found in the Miscellaneoussection at the bottom of the list (this example uses a prompt object named “sPrompt” and this will be referenced in the JavaScript).
clip_image003
5) And now the fun part! Drag an HTML Item object directly to the right of the prompt. Assign its’Description property the following value: prompt modifier.
TIP: Adding descriptions to your HTML Items makes it easier to identify them later when more than one is present in the report.
clip_image006
6) Now enter the following code into this HTML Item by either double-clicking it or select the HTMLproperty:
<script>
fW._textEditBoxsPrompt.onblur=validatePrompt;
</script>
This code will make our prompt run the “validatePrompt” function every time it loses focus.
7) Now, we will add a second HTML Item to top of the page to hold our functions. Once the HTML Item is added to the report, describe the item by going to the Description property and typing in “functions”. Your prompt page should now look like the image below:
clip_image008
8 ) The following code will allow users to enter a maximum of five (5) numeric codes separated by commas. Any other characters that are encountered will throw an error. The section for a proper validation was purposely left blank to allow readers to enter their own success message or routine.
<script>
var fW=(typeof getFormWarpRequest == “function” ?
getFormWarpRequest() :document.forms["formWarpRequest"]);
function validatePrompt()
{
str=fW._textEditBoxsPrompt.value;
if (!(str==null||str==”"))
{
str=str.toUpperCase();
str= str.replace(/ /g, “”); // remove all spaces
str= str.replace(/,+/g, “,”); // replace multiple commas by one
str= str.replace(/,$/g, “”); // remove trailing comma
str= str.replace(/^,/g, “”); // remove leading comma
var patvalidchar = new RegExp(“^[0-9,]+$”);
var pat3char=new RegExp(“^([0-9]{1,3},)*$”); // 3 digit code
var pat5char=new RegExp(“^([0-9]{1,3},){0,5}$”); //more then 5 codes
// characters other than numbers were used…
if (patvalidchar.test(str)==false)
alert(“Codes may be comprised of only numbers.”);
// codes are more than 3 digits long and only numeric …
else
{
if (pat3char.test(str + “,”)==false)
alert(“Codes must be at least three digits.”);
// more than 5 codes were entered …
else
{
if (pat5char.test(str + “,”)==false)
alert(“Please enter no more than 5 codes”);
// Enter code here for successful validation …
else
{
return true;
}
}
}
}
// Enter code here if Text Box is Empty …
else
{
alert(“No values entered.”);
}
}
</script>

How to Implement a Dynamic Page Break Using an Optional Filter


Page Breaking is a useful feature to offer report consumers. However, it’s often difficult to do this if the item you want to break on is dynamic. Here we show you how to do this with cascading, optional prompts while page breaking on the lowest level chosen.
Step by Step Instructions:
The following set of instructions show a sample JavaScript implementation in a Cognos8.2 environment, using the Cognos provided Go Sales and Retailers package. It was tested on IE 6.0 and IE 7.0.  JavaScript will need to be upgraded for Cognos 8.3 and above.
1. To get started, let’s create a simple list report with the following fields:
1
2.  Create a prompt page with product line, product type and product as optional cascading value prompts; name each prompt object with name “pLine”, “pType” and “pProduct” respectively.
You will have the Product Type prompt cascaded by Product Line, and the Product prompt cascaded by Product Type.
Hint: to name each prompt object click on the object then on the right properties panel underMiscellaneous ->Name
2
3. Add  optional filters “ pLine, pType, pProduct”  to the report query:
3
4. Test the report to make sure it is working correctly at this point
5. Add a new hidden text box prompt onto prompt page. Name it as “pLevel”, set default value to “pALL”.  This text box prompt value will be used to determine the lowest prompt level that a user selects.  When the user hits the customized “Finish” button” (see below) a JavaScript function will go through each prompt and dynamically set this hidden text box prompt value to the corresponding level the user has selected.
4
6. Delete “Finish” button on prompt page. Drag a new HTML item and create a new custom “Finish”  button using the following HTML code:
<button type=”button” name=”finish99″ id=”finish99″ onclick=”assignParamValue()” style=”"
class=”bp” onmouseover=”" onmouseout=”" onkeypress=”return preventSubmitEvent(event);”>
Finish</button>
7. Add another HTML item onto prompt page and paste in the following JavaScript:
<script>
var f=document.forms["formWarpRequest"];
function assignParamValue()
{
var tmp=”";
if (f.elements["_oLstChoicespLine"])
{
if( f.elements["_oLstChoicespLine"].selectedIndex>=0 )
tmp=’pLine’;
}
if (f.elements["_oLstChoicespType"])
{
if( f.elements["_oLstChoicespType"].selectedIndex>=0)
tmp=’pType’;
}
if (f.elements["_oLstChoicespProduct"])
{
if( f.elements["_oLstChoicespProduct"].selectedIndex>=0)
tmp=’pProduct’;
}
if(tmp==”") tmp=’pALL’;
f.elements["_textEditBoxpLevel"].value = tmp;
//uncomment for debugging
//alert (‘Page set breaks by ‘+document.forms["formWarpRequest"].elements["_textEditBoxpLevel"].value);
promptButtonFinish(); //submit request
}
</script>
8. Now add a new data item to report query, name it as “pagebreak by”. Use the following expression:
if (?pLevel? =’pProduct’)
then ([gosales_goretailers].[Products].[Product name])
else if (?pLevel?=’pType’)
then ([gosales_goretailers].[Products].[Product type])
else if (?pLevel?=’pLine’)
then ([gosales_goretailers].[Products].[Product line])
else (‘ALL’)
9. Set up page breaking for the report and group it by the “pagebreak by “ data item you just created:
5
10. Click on Page1, then on Properties Panel click on “Master Detail Relationships”. Define the master detail relationship from “pagebreakby” to “pagebreakby”.
6
11. Go back to report page. Drag “pagebreak by” data item to report title area:
7
12. Run the report. If you select two product types then the report should return two pages.  The report title should also dynamically change base on page break:
Prompt page:
8
Sample Report Page 1:
9
Sample Report Page 2:
10

Designing Effective IBM Cognos Report Studio Templates


In the past we’ve discussed the benefits of changing the default skins within your organizations different IBM Cognos environments, and we’ve also tackled the use of Layout Component References to help centralize and simplify repetitive report design tasks which can be otherwise time consuming. Now we will combine these concepts along with some new techniques in order to implement a single standardized report template for your entire environment, ensuring that your distributed reporting has a uniform and professional look and feel.

Step 1 – Prepare Your Environment

First we are going to create a new folder that will be used to store all of our custom template/branding content within our environment. Because this folder needs to be web accessible, it should be placed within the <Cognos Install>\webcontent folder for simplicity’s sake. In our example environment we will create the folder
C:\Program Files\Cognos\c8\webcontent\ironside
We will then create a sub folder called images which will be used to store all of our custom image content. In the future if we decide to add other types to files for use in branding or customizing our environment, we will create additional sub-folders to organize those files by their type (e.g. \css for Style Sheets, \js for JavaScript, etc.) Once we have created our images folder we will place all of our branding image content within it, and then make sure we enable directory browsing and WebDAV for this folder within IIS so that we may browse image thumbnails from Report Studio.

Step 2 – Create Layout Components

Once our environment is configured, and our images loaded onto our server, we are ready to begin creating our layout components for the portions of our template that we wish to centralize in order to simplify future changes or modifications to the template. Typically this is a header or footer that you will want to remain configurable in the event that logos or corporate standards change in the future.
  1. Open Report Studio and Create a New Report Template
  1. Customize the template header and footer to meet the standard needs of your organization.
  2. Be sure to encapsulate your new header and footer within named Block objects so that they can be used as Layout Component Reference objects in the template we intend to build.
  3. Save this template to a common area beneath Public Folders for which Everyone would have read, traverse and execute permissions. It is helpful to create a common administration folder in our environment where reusable objects can be stored.
There is no need to do any additional formatting to this particular template as we are only using it as a repository for Layout Component References. Save the heavy lifting for the next step.

Step 3 – Build Your Template

Now that our Layout Components have been finalized, it’s now time to build our template.  Templates can be used not only as a way to standardize look and feel, but also as a tool to guide report authors in our environment into following report building best practices. You may be inclined to create a separate template for each possible report type (List, Crosstab, Chart, Repeater, etc) but please resist the urge. It’s much easier to maintain a single blank report template, and properly configure it so that any and all query object types are formatted to your specifications.
  1. Start by creating another new Report Template in report studio.
  2. Before doing anything, hover over the Page Explorer and select the Classes entry from the list to enter the class editor view. From here we can edit the look and feel for any object that will be created using our template. This is the preferred method of editing report style sheets because it does not impact any global settings within your environment (as opposed to editing the Global Style Sheet) and would permit you to dictate look and feel on a template-by-template basis, enabling you to have multiple templates in your environment if need be.
  3. In our template, we will edit and extend the default classes so that the list and crosstab objects have grey row and column headers instead of the default light blue.
  4. Once we are happy with how our global styles have been extended, we can now drag and drop the header and footer layout components that reference the template we saved in Step 2.
  5. At this point we may also like to add features to our template that encourage report authors to use good report design practices. An example of this would be adding a prompt page to our template and also adding place holders in our report page headers to display prompt parameter values that would give the report the proper context.
  6. We now save our newly created report template to the same folder as our layout component reference repository, and proceed with testing the report for all possible scenarios before we proceed with integrating the template into the Report Studio interface.

Step 4 – Install Your Template in Report Studio

Finally we have completed thorough testing of our template, and received the blessing of our end users. It’s now time to integrate our template into the Report Studio interface for ultimate ease of use.
For detailed instructions on how to do so, please refer to the chapter on customization in the IBM Cognos Administration and Security Guide.
Tip: If you don’t see your customizations taking effect in Report Studio, try clearing your browser cache.
At this point, if we need to make a global change to our headers and footers, all we need to do is edit them in our Layout Component Reference report in our environment and the changes will flow through to each and every report that was created using this template (as long as the report author has not overridden them at the report level). If you have multiple Cognos environments (Dev, QA, Production) it’s important that this repository report exist in the exact same path in each to ensure that the links to our layout components are not broken as we migrate content to production.

Performing Data Warehouse Validation with IBM Cognos Report Studio


Reporting should start with a “single source of truth” and end with a “single version of truth.” Delivery of accurate reporting information is paramount in the day-to-day operations of every organization. Some of the methods for maintaining data Integrity (within the data warehouse) would be to apply referential integrity and maintain primary keys on tables. In addition, associated ETL processes can utilize checksums, or record counts, when loading the warehouse. Once the data is in the warehouse, the next step would be to model the data for exposure to the end-users.
Models can easily become extremely complex and the accuracy of the reporting MUST be ensured for your end-user community. One source of truth, one version of truth, and overall trust in the data is crucial for the long-term success of your warehouse. So, is there an optimal method to proactively determine the accuracy of the model and the data being reported? Unfortunately, there is no “out of the box” solution, but a capable Report Studio user can easily build a report to ensure general data quality of the IBM Cognos model. The outline below represents the steps for building the appropriate queries with a visual diagram representing two facts being evaluated.
1. Build a Fact Query
  • Sub-Category = ‘Fact’.
  • Fact Count = Count (or sum) a metric in your fact.
2. Build a Dimension Query – Line of Business Dimension
  • Sub-Category = Case When any field in dimension = ‘X’ Then ‘LOB’ Else ‘LOB’ End.
    Note:
     This fill forces a join to the dimension being evaluated for integrity.
  • Fact Count = Count the exact same metric from your fact query.
3. Repeat step 2 (Build dimension queries) for each dimension in your model by modifying the Sub-Category to reflect the dimension being evaluated.
Your data items for each of these queries should appear as follows:
4. Union the results from the above step.
5.  In the resulting query from step 4, utilize case statements and a list report (as opposed to a crosstab) to allow more control of my desired output (as outlined below):
  • Query Subject = ‘Name of Your Fact being Evaluated’.
  • Fact Count = Case When Sub-Category = ‘Fact’ Then Metric Else 0 End.
  • Time Variance = Case When Sub-Category = ‘Fact’ Then Metric
When Sub-Category = ‘Time’ Then (Metric * -1)
Else 0
End
  • Repeat step c for each Sub-Category in your union (remember to modify the dimension being evaluated in each case statement).
6. Repeat step 5 for each fact being evaluated.
7. If more than one fact is being evaluated, union all the unions created in step 4.
Your data items for the union would look similar to the screenshot below:
8. Create a list report with all the data items created in the above steps.

The ultimate goal is to have a report that counts the exact number of records in your fact table and each dimension column, from the list report, with a value of 0. A 0 value indicates model referential integrity has been validated and thus no records are dropping from reporting.
The above technique utilizes a life-to-date approach for all records in the warehouse. A prompt page with date filters can easily be applied to this solution. Historical data can unexpectedly and unknowingly be altered and thus I have used the following approach for scheduling reconciliations after the latest data has been loaded to the warehouse:
  1. Business Days – Report runs form the past seven calendar days.
  2. Saturday – Report runs a year-to-date reconciliation.
  3. Sunday – Report runs a life-to-date reconciliation.

IBM Cognos 8 Advanced Reporting – Hidden Prompts


In the past, we have introduced techniques around dynamic prompting by utilizing a number of Cognos Report Studio built-in features. Occasionally there are scenarios that will necessitate the need to set a report parameter without prompting the user to select a value. For instance, there may be a case where the report developer needs to pass both the selected year and the previous year to a stored procedure or pass in a calculated prompt value that would be based on previously selected prompt values. While there are a number of solutions for such scenarios, in this article we will focus on a Javascript based technique to provide the necessary functionality.
Development Environment
IBM Cognos 8.4 using Internet Explorer 6.0 or Higher
Note: This technique uses JavaScript against underlying report objects in a Cognos BI report. For this reason, there is no guarantee that this solution will work for other versions of Cognos due to the structural differences within the applications components when compared to the tested version. . 
Step by Step Instructions
  1. Launch report studio, select Go Sales(query) package.
  2. When prompted, choose create a new report with a list template.
  3. From the Sales(query) namespace, drag Quantity and Revenue data items from the Sales query object. Add in the Year data item from the Time dimension. Your list report should appear as follows:
  4. Navigate to Page Explorer -> Prompt Pages, drag in a new prompt page.
  5. Drag a value prompt to the prompt page, and set the parameter as “pYear” when prompted to create a new parameter in the prompt wizard     .
  6. Enter “Year” as the name of prompt object (Under properties/Miscellaneous)and click on Finish.
  7. Add in a text item to describe the prompt.
  8. Under the prompt properties, add in static choices values: 2005, 2006, 2007.
  9. Set the data format property to number with zero decimal places.
  10. Drag a text box prompt onto the prompt page. Set the parameter name to “pYearLess” in the wizard and set its object name to “YearLess”.
  11. Your prompt page should now resemble the following:
  12. Delete the default Finish button.
  13. Add a HTML item after the Next prompt button.
  1. Type in the following JavaScript code in the HTML item:
    <button class=”bp” onClick=”setYearPrompts();”>Finish</button>
    <script type=”text/javascript”><!–
    function setYearPrompts()
    {
    var fW = (typeof getFormWarpRequest == “function” ?getFormWarpRequest() : document.forms["formWarpRequest"]);
    fW._textEditBoxYearLess.value=fW._oLstChoicesYear.value -1;
    promptAction(“finish”);
    }
    //–></script>
  2. Navigate to the report page and add in the following filter to the report:
  3. Run report and you will notice that the report is actually filtered by the hidden prompt value (User selected year minus one).
JavaScript is a very powerful technique available to report authors in IBM Cognos Report Studio. However, in many cases the code is tied to the underlying Cognos web page structure, which in return brings in some overhead on maintenance and upgrade oriented activities. For this reason, it is imperative that Javascript is used judiciously during report development.