Tag Archiv für Java Script

How to show/hide a parameter section in a Report

Hi,

For a customer I was developing a new report this week. He asked me to implement a section in the report header where you can see what parameters are selected in the report. Because there  are a lot of parameters in my customer’s report he wanted some fancy function so you can easily show or hide this parameter section.

The solution works with two html items, which just contain a <div …> and a </div> tag and a Java Script function which shows or hides the div block. The example report doesn’t contain a list or something. It’s just having the parameter section on the report page and a link to show/hide it. But you can easily implement it in your reports as well. It’s also not very beautiful. For example you could use a nice picture instead of a link.

As I’ve written before you need two html blocks.  These blocks contain the following code:

HTML Block 0(JavaScript)
<script type=“text/javascript“ >
 
function ShowHideDIV(){
   if (document.getElementById(‚testdiv‘).style.display != ’none‘) {
        document.getElementById(‚testdiv‘).style.display = ’none‘;
   }
   else {
       document.getElementById(‚testdiv‘).style.display = ‚block‘;
   };
};
</script>
HTML Block 1
<a href=“javascript: ShowHideDIV();“> Show/Hide parameters </a>
 
<div id=’testdiv‘>
 
HTML Block 2 </div>

This solution uses the CSS (Cascading Style Sheets) which describe formatting properties of an HTML document.  As the Cognos report results are normally HTML documents as well you can use this knowledge to dynamically set or unset the property for hiding a div block. If you want to enhance this solution you can pass the name of the block via a variable to the function.

Anyway these HTML blocks must then be inserted to the report like this:

BLOG_0024_PIC01_Overview_Report_Page

 

The very first block in the page content area must be the HTML item with the Javascript. Then around the table or text-items with the parameter description you have to place HTML Block 1 and HTML Block 2. I’ve chose a table to represent the prompt parametes. After the HTML Block 2 you can insert the report data itself.

The examples used in this article can be found at the very end of this article as zip-file. I will continue this series soon and we will then deal with some useful functions you can use if you are working with the rollup or cube statement.

If you are interested in this or other advanced Cognos/SQL topics you can also attend training on my corporate homepage. At the moment my open courses are only available in German. Inhouse training and online courses are also available in English language. So check out my open trainings (German) or my online courses (English)!

Download

BLOG_0025_Example_Report.zip

Cognos & JavaScript – Part I: Date prompts

Why to use Java Scripts in Cognos

In this issue I will take a closer look at using Java Scripts in Cognos. That gives you the advantage of enhancing your reports in Cognos Report Studio by further features and functions. The disadvantage might occur when you are upgrading to a new cognos version. In this case you should check your scripts whether they still work fine. Some examples for the use of Java Scripts are: dynamically setting date prompt standard values, hiding & showing a parameter area withing the report, marking rows in a table by clicking on them with the mouse, etc.

One of the most useful topics in this case is to set the standard setting of a date prompt. Normally it is set to the current day, but quite often you want the day before cause the latest data in your DWH is from the last day. I will show today how to access these controls with a small script within Cognos Report Studio.

Accessing the date prompt

To do so you have to create a small report. It doesn’t really matter what exactly the report is doing, but it needs a prompt page and at least one date prompt.

Now you have to add a HTML item. With this control you can add your own HTML code to a report page or prompt page. You can also add Java Scripts with this item. Now we want to access the already set value of your date prompt. In order to do this we have to set the name property of this control. For example you could name it “Test”.

Next we have to add the following code snippet:

<script language=”JavaScript”>

var frm = getFormWarpRequest();
alert ( frm. txtDateTest.value );

</script>

Add this to your HTML item and run the report. There should pop up a small message now which contains just the value of your date prompt. The first line is needed to receive a handle to the form.  For this we use a cognos built in function, named getFormWarpRequest(). In the second line we use this handle to access the date prompt. The prompt objects are created by a type descriptor directly followed by the name of your control. In the case of our date prompt the type descriptor is “txtDate”. The property “value” contains the selected value of the date prompt. To access other prompts you need the following type descriptors:

 Controlling the whole prompt page

Prompt Type JavaScript Prompt name
Date edit frm.txtDate<Name>
Text edit frm._txtEditBox<Name>
List Box frm._oLstChoices<Name>
Drop Down List frm._oLstChoices<Name>
Radio Buttons Group frm._oLstChoices<Name>
Chech Boxes frm._oLstChoices<Name>

 

Setting the date prompt can be done with the following script:

<script language=”JavaScript”>

// getting the systemtime and building a time string.
var today = new Date();
var datestr = „01.“+(today.getMonth()+1)+“.“+today.getYear();

// receiving a handle to the from and setting the date prompt
var frm = getFormWarpRequest();
frm. txtDateTest.value =datestr;

</script>

This sets your date prompt “Test” to the first day of the current month.  The getMonth() function returns a value between 0 and 11. That’s why we have to add 1.

In the next episode of this blog I will describe how to access List boxes, Drop Down Lists, etc.

If you are interested in this or other advanced Cognos/SQL topics you can also attend training on my corporate homepage. At the moment my open courses are only available in German. Inhouse training and online courses are also available in English language. So check out my open trainings (German) or my online courses (English)!