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:
</div> <script> /* 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 */ document.getElementById('mySnS').getElementsByTagName('input')[5].click(); </script>
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.
Do you know what should I do if I have two search prompt where the code must be put ? The code works when i have one prompt but when i have two – it doesn’t.
When you have two select and search prompts simply wrap both of them in HTML items with different IDs.
So you have mySnS and mySnS2. Then anywhere after the second one on the page:
This worked great thanks!
It works. Thanks Paul
Hi Paul
Thanks, this works really nicely. Is it possible to apply it to the choices element of the Select and Search prompt?
Hi Paul, I just consolidated 2 codes you posted here in one solution, this one (default selection) plus the window resize:
*Prompt here*
var e=document.getElementById(‘selectSearch’);
var myselect = e.getElementsByTagName(‘select’)[0];
if(myselect.childNodes.length>0){myselect.style.width=”}
/* 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
*/
document.getElementById(‘selectSearch’).getElementsByTagName(‘input’)[4].click();
Thank you for posting the code, works perfectly!
In select & Search prompt, we have a “Options” which we need to EXPAND to select the below search options. Is there a way to keep ^^ always in expanded form so user can see the options and select?
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
Try the following:
Hi Paul
Been searching the forums without success, so……
How do we go about this in Analytics?
Cheers
Working on an update for this soon.