While IBM is promising searchable tree prompts in Cognos 11.1.7 (hopefully), many cognos instances won’t upgrade to that soon. Also, it’s likely that prompt will only work in interactive mode, so a non-interactive mode prompt would be very useful.
The technique I’ve come up with doesn’t use any JavaScript, and works just as well for non-interactive mode. The only downside is that it involves refreshing the page, but the only query that changes should be query feeding the tree prompt, so it shouldn’t be too bad.
For the purposes of this post, I’ll build it in interactive mode.
To start, let’s build the structure of the search. Create a table with 2 rows, 2 columns, and merge the bottom two cells.
Top left: Drag in a text box prompt, parameter name: “ProductSearch”
Top right: Drag in a prompt button
Bottom: Drag in a tree prompt, parameter name: “Product”. Don’t select anything to feed the prompt, we’ll do that later.
When you’re done, it should look like this:
Now we have to define the data item feeding the tree prompt. In this case this is the code we want:
#prompt( 'ProductSearch' , 'string' ,'[Sales (analysis)].[Products].[Products].[Product line]' ,'union(filter(descendants([Sales (analysis)].[Products].[Products].[Products],1,self beforewithmember after),lower(caption(currentMember([Sales (analysis)].[Products].[Products]))) contains lower(' , '' , ')),'+promptmany('Product','mun','emptySet([Sales (analysis)].[Products].[Products])','set(','',')')+')' )#
It seems complicated, so let’s go over step by step.
First, look at the ProductSearch parameter. If it is null, then take the Product line level from the hierarchy. This is the way tree prompts behave normally.
Next, if there is a value in ProductSearch, let’s filter the ENTIRE hierarchy looling for the specific string. If a user types in, “polar” the expression would look like:
filter(descendants([Sales (analysis)].[Products].[Products].[Products],1,self beforewithmember after),lower(caption(currentMember([Sales (analysis)].[Products].[Products]))) contains lower(‘polar’))
And finally, we union the already selected Products, if any, onto that set. On the first search it might look like:
union(filter(descendants([Sales (analysis)].[Products].[Products].[Products],1,self beforewithmember after),lower(caption(currentMember([Sales (analysis)].[Products].[Products]))) contains lower(‘polar’)),emptySet([Sales (analysis)].[Products].[Products]))
Assign that data item to the tree prompt, and let’s see it in action.
It’s working, but it doesn’t look great. You can drag a text item into the prompt button, and resize things to make it a little more inline.
Report XML below
search-tree-report.xml (1086 downloads)
Hello Paul!
Thank you very much for sharing this amazing workaround with us!
fyi: My #prompt expression only works with ” ; ” instead of ” , ” as a separator. I had to do some modifying but then it worked just perfectly. Do you have any idea why? Is it because of the language CA is installed or used?
I am using CA 11.1 R5 and the default language is german.
Nevertheless many thanks for your great work.
Theo
Paul,
This is an amazing implementation, simple yet powerful.
I am trying to take it one step further and have the selection change as I type
My first attempt was to create a custom control or a page module to simply use the setValidator method to force a reprompt on every letter typed, but could not find a way to invoke the reprompt method.
any suggestion?
Hey Itzik, sorry for the late reply. PM2 has come up with a JS searchable tree prompt control. It really only works when you have a hierarchy with 2k or fewer members. If this meets your needs, send me an email and I’ll see what I can do for you.
I’ve been thinking of an AJAX style tree search prompt, but haven’t had the time to build it yet.
Thanks Paul for this powerful and effective implementation. I was trying to make it work for multiple values instead of just just one but failing miserably. For e.g I want to search for Star Gazer 2, Star Gazer 3 and Star Gazer 6 in a singlesearch