Cognos & JavaScript – Part II: Dropdown prompts

In the second part of the Java Script series we want to access drop down lists. That also includes list boxes, radio button groups and check box groups as they work based on the same principles.

Again we are focusing on dates to be selected. In todays’ issue we need a Drop Down Box with months. The USE Value should be some number like 201201, 201202, 201203 and so on. The display value can be as you want it to be. It doesn’t really matter if you add the values by static choices or a query. Let’s name the Box “DropDownTest”.  My examples are based on the three entries above as static choices.

The general syntax to access for example the 2nd item in the drop down box is as follows:

<script language=“JavaScript“>

var frm = getFormWarpRequest();

alert (frm._oLstChoicesDropDownTest.options[3].text);


With the above snippet you can read the display value of the second item in the list. options[] is the array that contains all the items of the list or dropdown box. The parameter name and a separator line ‘———–‘ are normally also part of this array. Array indexes in Java Script starts with 0. That’s why we have to use an index of 3 for accessing the first “real” item.

We have several properties in the options[] array that might be interesting:

  • text -> display value
  • value -> use value
  • selected -> true, if item is selected.
  • length -> method to return the number of items in the array

With the next script you can select an item of the list:

<script language=“JavaScript“>

      var frm = getFormWarpRequest();



Now the 3rd item of the list is selected, i.e. the first relevant item.

With the above scripts you can easily select the value that is relevant in your case. For example you could check for the current date (also look at the article: Cognos & JavaScript Part 1) and depending on that you can select the current month or one month before.

In the next part of this series I will explain how to set up an event handler to react on choices that the user made to certain prompts.

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

3 Kommentare

  1. Tony van Muyden sagt:

    You are using here internal structures from the IBM Cognos Interfaces. This is and was never supported. The main reason the Prompt API was added to the ReportStudio Guide finally many years in Development is from pressure within IBM Cognos Support to release it. You can only use the official Prompt API with Version C 10.2 and up, all other older javascript published and used in Technotes is not supported. this means you can not log cases for it, and IBM Support can not help you in any further development this way. Thanks TJ

  2. Scott Johnson sagt:

    Tony is right. You should rewrite this article using the Cognos Javascript API. It’s much clearer and it’s supported by Cognos. It’s documented here:

    • FabianGaussling sagt:


      yeah you two guys are maybe right. At least it makes sense from version 10.2. on to use the prompt api. But there are also people still using older versions of Cognos. They can’t use the prompt api as it is introduced with 10.2. But I think I will write another article about the prompt api and post it here soon. Thanks for your comments!


Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.