Cognos 10 Report Studio Tutorial

Show and Hide Inline Prompt

In this article, we will learn how to show and hide inline prompts in IBM Cognos 10 Report Studio.

Following is the demo video what we will achieve in the article.

As shown in the demo video we have two different solutions to achieve it. 

  1. With Value Prompt
  2. With JavaScript

For both the demos, we will use the following sample report. Download and import it in the report studio.

FileDownload
Show and Hide Inline Prompt Start.xmlLogin to Download

If you want to know How to Restore a report using an XML file, you can refer to this article.

Show Hide example, with Value Prompt

In this report, we are using a value prompt, the parameter and the conditional block to control the visibility for the inline prompt. Open the sample report. The sample report is a single page report with the inline prompts. On the report page, we have a table with three rows. The first row is empty, in the second row we have all the inline prompts and in the last row, we have our list. 

From the toolbox drag and drop a value prompt in the first row. Next, in the prompt wizard dialog, provide the parameter and click on the “Finish” button to save the new value prompt. 

It will create our value prompt. After that, we need to change the user interface for the value prompt. Select the prompt, from the property change the user interface to the radio button. Also, when a user changes the prompt value, we need to refresh our report. To achieve this, enable the Auto Submit property. Our value prompt is almost ready. To add the options set the static choice. Add two values Show and Hide with key 0 and 1.

Next, we need to define the default selection. From the property click on the “Default Selections” and provide a default value.

The value of the show is 0. So, we need to add 0 in the default selection.

Now to show and hide the inline prompts we need to add the condition block. From the toolbox drag and drop the condition block in the second row. Next, to control the visibility sets the block variable. In the block variable dialog, create a new Boolean variable. In the expression dialog for the new Boolean variable use the following expression “ParamValue(‘pShowHide’)=’0’”. Click on the “OK” buttons to save all the changes.

We are almost done with all the changes. Next, we need to display the inline prompt when our condition is true. Select the current block to “Yes” and then move all the prompts in the condition block.

Save your report, validate, test and run the report.

Show Hide example, with JavaScript

We achieved our requirement to show and hide the inline prompt. But in the above approach, we have two extra page refresh. The first is when we clicked on the “Show” and the next one is when we click on the “Hide”. Assume our report will take 10 seconds to load. It means we are wasting 20 seconds for the end user. To avoid the waiting we will use the JavaScript method. Open the “Show and Hide Inline Prompt Start.xml” report.

Report structure is same, we are using a JavaScript, and the HTML Item to control the visibility for the inline prompt. Open the sample report. The sample report is a single page report with the inline prompts. On the report page, we have a table with three rows. The first row is empty, in the second row we have all the inline prompts and in the last row, we have our list.

To create the radio buttons using HTML drag and drop the HTML Item from the toolbox and add it in the first row. Use the following code in the HTML Item.

Code

<input type="radio" name="ShowHide" onclick="ShowHidePrompt(this.value)" value="0" checked /> Show <br/>

<input type="radio" name="ShowHide" onclick="ShowHidePrompt(this.value)" value="1" /> Hide
<script>
    function ShowHidePrompt(value)
    {
        if(parseInt(value) == 0)
            document.getElementById("divPrompt").style.display="block";
        else
            document.getElementById("divPrompt").style.display="none";
    }
</script>

In the above code, we have HTML input to create two radio buttons “Show” and “Hide”. After that, we have a script tag to add the JavaScript code.  In our JavaScript code, we have a function which is used to control the visibility for a div element with id “divPrompt”. Next, we need to create our “divPrompt” element. Add two HTML items before and after the inline prompt table. Refer the following image for more details.

In the first html item, add the following code.

Code

<div id="divPrompt">

In the second html item, add the following code.

Code

</div>

Now, our inline prompt table is enclosed in the html “div” element. We can control the visibility for the “div” element. Because the prompt table is inside the div element, it will not visible if the parent is hidden. We are controlling the visibility for the “div” element using the following two JavaScript lines.

Code

document.getElementById("divPrompt").style.display="block";
document.getElementById("divPrompt").style.display="none";

The first line is to display the “div” element. And the second line is to hide the “div” element.

Save and run the report.

Our Show and Hide functionality are working fine. But when we click to change the report page, it will not retain the prompt state. To fix it check this demo.

How we achieve it? You can check it in our complete IBM Cognos 10 or IBM Cognos Analytics Tutorial Series.

FileDownload
Show and Hide inline Prompt VP End.xmlLogin to Download
FileDownload
Show and Hide inline Prompt JS End.xmlLogin to Download
0 Comments
Leave A Comment

Please login to post your valuable comments.

share