The search prompts haven’t gone through many changes in Cognos since version 8. Despite many requests, changing the default search type (from starting However, one big whopping change is the popup element containing the search items is no longer inside the search control. Instead it’s hidden somewhere else on the page, with nothing tying it to the actual control.
This makes the old script useless, and finding that popup is incredibly difficult. In Cognos 11.1 the method for finding the popup is promptElement._FZH._9FF while in 11.0 it’s promptElement._REG._FZD. This obfuscation means we have to rely on trickery and shenanigans.
Look away now if you value your sanity
prmptElmLoop: //yes I'm using a label here. I'm not feeling at all defensive about it. for(var a in $(prmptElm).find('.clsComboBox')[0]){ if(typeof($(prmptElm).find('.clsComboBox')[0][a])=="object" ){ //if the object itself is an object... for(var b in $(prmptElm).find('.clsComboBox')[0][a]){ //...dig deeper. if($(prmptElm).find('.clsComboBox')[0][a][b].classList=="po_clsListView_dropdown po"){ //this identifies the actual popup element. $($(prmptElm).find('.clsComboBox')[0][a][b]).find("tr:eq("+(opt-1)+")").trigger('mousedown'); //finds the correct table row and performs a mousedown. if(resizeOptions) prmptElm.style.width='unset'; break prmptElmLoop; } } } else continue; }
In order to find that options popup, we’re looping through the prompt element and examining each attached method. If it’s an object, we go deeper. Finally we’ll find a method that’s a pointer to the element (which we can identify using the class), and then it’s just a matter of triggering a mousedown event on the correct row.
In order to use it, you need to give the search prompt a name, like mySnS. The custom control needs to have the following configuration:
{
"promptName": "mySnS",
"option": 2,
"resizeOptions": true
}
That’s looking for the prompt name mySnS, selecting “Starts with the first keyword and contains all of the remaining keywords”, and then resizing the options list.
The options are as follows:
* 1 – Starts with any of these keywords * DEFAULT
* 2 – Starts with the first keyword and contains all of the remaining keywords
* 3 – Contains any of these keywords
* 4 – Contains all of these keywords
Important note! I’ve tested this on 11.0.5 and 11.1.0. I have no reason to think it won’t work on other C11 versions but I can’t promise it will continue working. Hopefully methods like this will be exposed with a consistent name in future versions.
The attached zip contains the report XML and the JavaScript.
search-Default.zip (7551 downloads)
Funny that you posted this yesterday and it was one of the first things I got asked about in the office today. Thanks for the help!
Hi Paul,
have you had a chance already to verify this great functionality (which every customer needs an IBM/Cognos is not able deliver for how many decades …. ) on a CA Version 11.1.2 ?
We upgraded a customer which relies on your JS solution. Since they run on 11.1.2 the JS is failing.
ReferenceError $ is not defined etc. etc.
Thanks a lot for your feedback
br
Christian
It looks like there were two problems.
1. There was a null attribute in one of the objects, so the fix is to add a check for that.
2. The classList of the hidden table changed, so we had to account for that.
The fix is to change line 45 to
I’ve also updated the file.
Hi Paul,
thanks for the quick reply.
I implemented your fix but unfortunately still getting errors when running the report:
Type error : cannot read property ‘classList’ of null at defaultSnS.initialize
Anything else I need to take care of ?
Thanks for your support & br
Christian
I was able to get past the error by changing line 45 to the code below:
if(($(prmptElm).find(‘.clsComboBox’)[0][a][b] && $(prmptElm).find(‘.clsComboBox’)[0][a][b].classList !== null && $(prmptElm).find(‘.clsComboBox’)[0][a][b].classList !== undefined) && $(prmptElm).find(‘.clsComboBox’)[0][a][b].classList.contains(“po_clsListView_dropdown”)){
Hope this helps.
Hi Mark,
I have tried the above code in line 45 but im getting an error as Referenceerror : ? is undefined at SnSDefault.prototype.initialize.
Can you please help me on this. I need this function to work on analytics
Mark / Ashu.jit,
Were either of you able to solve this? I am trying to use this as well in 11.1.5 and getting the same error.