Quickie: Changing default option in a Select and Search Prompt

I’ve been somewhat negligent in responding to the comments lately. One of the most common questions appears to be how to change the default option in a select and search prompt.

The following should work for all versions of Cognos.

Put an HTML item before the prompt, with the expression:

<div id="mySnS">

Now put another HTML item after the prompt with the expression:

/* Select and search options
 * 2 - Starts with any of these keywords * DEFAULT
 * 3 - Starts with the first keyword and contains all of the remaining keywords 
 * 4 - Contains any of these keywords 
 * 5 - Contains all of these keywords 

The script will locate the mySnS element that surrounds the prompt, generate an array of the input tags, and click() on the one specified. In the example, 5 is selected so it will click on the sixth element (0 based array).

Going through the Cognos JavaScript files, it looks like there is supposed to be a function in the new Prompt API that would let you do it in an easier manner, unfortunately it appears to be an incomplete function, maybe it will be released in the new fixpack.

In theory, you should be able to do something like the following:

var acme = {};
acme.getControl = function(promptName) 
  var ocr = cognos.Report.getReport("_THIS_");
  return ocr.prompt.getControlByName(promptName);

acme.getControl('mySnS2').setProperty( "caseInsensitive", false);
acme.getControl('mySnS2').setProperty( "searchType", "containsAny");

But, as I said, the function doesn’t appear to be complete in this version. Use the other method for now.


One Response to Quickie: Changing default option in a Select and Search Prompt

  1. Rafa F. Lima says:

    Hi CognosPaul,

    I’m using this javascript code to define a default select on SnS prompt.
    However, if user selects another option and do a search, the prompt backs to mark the default option instead of to keep the previous selected option, like works a native SnS prompt.
    Do you have any idea to improve this code to accept this behavior?
    Thanks in advance.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: