Purchase your Section 508 Compliance Support guide now!

Purchase your Section 508 Compliance Support guide now!

Validating a list box prompt

Validating a list box prompt

By Sampath K Maduri, BI Consultant, NYK Business Systems Americas Inc.

Report authors may be asked to restrict the number of values selected on a list box prompt. This can be achieved with conditional blocks or javascript.

This technique restricts the user to select only a given number of values from a list box. This technique is based on the Go Sales and Retailers package that is provided with IBM Cognos 8 BI. The technique has been tested on IBM Cognos versions 8.2, 8.3 and 8.4.

Steps

  1. Using the Great Outdoors Company package create a prompt page and drag a value prompt onto the report. Name the new parameter Parameter1 and click Next.
  2. From Create Filter, select the package item as staff name from sales reps query subject and click OK. Select in from the Operator list and click Next. Select staff name from sales reps query subject for values to display and click Finish.
  3. Change the value prompt Select UI option to List Box, Multi-Select to Yes and set the Name property to StaffName.
  4. Drag an HTML Item above list box prompt and copy and paste the following javascript -
     
    <script language="javascript">
    function show()  
    {
    var count = 0;
    var selOpts = document.forms["formWarpRequest"].elements["_oLstChoicesStaffName"].options;
    for(var i = 0, max = selOpts.length; i < max; ++i)
    {
    if(selOpts[i].selected)
      {
    count= count+1;
      }
     }
    if(count>10)  // User can select maximum of 10 values from List prompt.
     {
    alert("You have selected " + count + " Values, Please select only 10 or less values");
     }
    else
           {
    promptButtonFinish();
           }
    }
    </script>

    NOTE : If using IBM Cognos 8.3 or IBM Cognos 8.4 replace the line .

    var selOpts = document.forms["formWarpRequest"].elements["_oLstChoicesStaffName"].options;

    with

    var selOpts = getFormWarpRequest().elements["_oLstChoicesStaffName"].options;

  5. From the Toolbox, drag another HTML Item under the list box prompt and copy and paste the following code -

    <button type="button" name="Validate" class="clsPromptButton"
    style="font-family:Arial;font-size:10pt;font-weight :bold;width:2cm"
    onClick="show()"> Finish </button>

Now when you run the report, you can select a maximum of ten sales reps from the list box prompt.  If your selection exceeds ten values, the system will alert you with a message to select ten or less sales reps from the list box.