Tag Archiv für Data prompt

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)!