Wednesday, March 7, 2012

Hide "Select All / Deselect All" Link in Value Prompts

Keywords: Value Prompt - Show or Hide - Select All / Deselect All - Javascript - Report Studio - Cognos 8.3 - Cognos 8.4

Business Case:
Business users want  the "Select All / Deselect All" link displayed under mulit-select Value Prompts to be hidden.  This is usually requested when the value prompt has hundreds or thousands of values and they shouldn't all be selected at once.

Note: To limit the number of options a user can select at a time, refer to the script in this article: Validate Value Prompt using Javascript

Implementation:
The links displayed in the prompt page are HTML elements. So, we can use Javascript to hide them. There are two different scripts that can be used to achieve this.


Note: The scripts in this article are available in IBM Knowledge Base (Link to IBM Knowledge base Article.)

Script 1: Use IBM's built in Object Names and Methods to hide the link
  • The script works in Cognos 8.3 and 8.4
<script type="text/javascript">
var a = document.getElementsByTagName("A");
for( var i = a.length-1; i >= 0; i-- )
{
    var link = a[i];

    if( typeof(link.id) == "string" && link.id.match(/PRMT_(SV|LIST)_LINK_(DE)?SELECT_/) )
    {
        link.parentNode.removeChild(link);
    }
}
</script>
  • To use this script, place an HTML Item after the value prompt and place the script inside this item.
  • The advantage of this script is that, it's a simple one step approach.
Script 2 - Alternate more generic approach (not dependent on internal prompt names)
  • Add an HTML item to the left and right of the value prompt in the Report Studio
  • For the first HTML item (left) add the following script:
<span id = "A1">
  • For the second HTML item (right) add the following script:
</span>
  • Add an HTML item at the bottom of the prompt page next to "Run" button and add the following script for the third HTML item:
<script>
var theSpan = document.getElementById("A1");
var a = theSpan.getElementsByTagName("A");

for( var i = a.length-1; i >= 0; i-- )
{
    var link = a[i];
    link.parentNode.removeChild(link);
}
</script>

8 comments:

  1. Alternatively, you could use the built in functionality of going to the page explorer fly-out menu, choosing classes, highlighting the "Prompt control hyperlink" class, and changing the Box Type to none. Saves on having to upgrade your java scripts when you upgrade to new versions of Cognos!! :-)

    ReplyDelete
  2. Hi.. I didn't think of this. That's a great suggestion. Thank you.

    ReplyDelete
  3. can you explain this. I tried but not able to do.

    ReplyDelete
    Replies
    1. Hi, I have given the step by step instructions in the article. Not sure how else I can explain this.

      Delete
  4. Hi
    As of Cognos 10 you can edit the Select all/Deselect All text with property fields on the prompt controls. If you set the text to an empty string, the link will not be shown at all.
    Then you wouldn't have to use JavaScript (or hide all link texts for all prompts in the report, as you would if you set Prompt control hyperlink class to BoxType None).

    ReplyDelete
    Replies
    1. Thanks!! I will include it in the notes.

      Delete
    2. thank you, saved my day

      Delete
  5. It works in cognos 10 also...

    ReplyDelete