Auto-Expand Tree Prompt in Cognos

Here’s a javascript solution that will automatically expand tree prompts in Cognos


There are two HTML tags required for this to work. Before the tree prompt, you need:

<span id="TreeName"></code>

and after the tree prompt, you need:


<script type="text/javascript">

	setTimeout (function() {document.getElementById('TreeName').getElementsByTagName('img')[0].click()}, 1000);


The script works by:

  1. Waiting 1000 milliseconds for the prompt to be loaded
  2. Finding the span that contains the ‘TreeName’ tree prompt
  3. Finding the first img element within that span. Note: For this solution to work, you must hide adornments
  4. Sending a click action to that element.

The full XML of this solution against GO Sales is available here.


  1. Marius says:

    Hi Andrew,

    Great tip and example you got here, thank you very much. I am testing it on Cognos 10.2.2 and it seems to be working fine but only expands one level down. Is it possible to have it expand multiple levels?

    For instance in product dimension of GO Sales could you have it expand from Product line and all the way down to Product:
    Product line
    Product type


  2. Andrew Mosey says:

    Hello Marius, and thanks for making the first comment on this blog 😀

    I think there would be challenges using this technique to expand a second level via javascript – certainly we’d need to build a few delays into the script as Cognos will only expand one checkbox at a time. Also the delays seem to be cumulative, it’d require quite a bit of tinkering to get it working I imagine.

    Hope this helps,

  3. Tanu says:

    Hi Andrew

    I think I have the same scenario. I need auto expanded Tree prompt and my tree prompt has a total of 7 levels, and by default I want it to expand till Level 4. How can I achieve this ?

    Thank you.


    • Andrew Mosey says:

      Hi Tanu,
      I’ve not found a way to expand these tree prompts out further than the first level in a robust manner. We also have a 8 level hierarchy and it can be a real issue for adoption of the solution.

  4. Dawna says:

    I love this solution. Thanks for sharing. Question…how do I expand this to do multiple tree prompts? Just giving the second tree prompt a new id name is not enough. Thank you.

  5. Andrew Mosey says:

    Hi Dawna,

    This should work for multiple tree prompts, just be sure to have the opening and closing script around each tree, and update the ids to match in each case.

  6. Prasad Loke says:

    Hello andrew, will this work in cognos analytics 11.0.6 as well?

    I am trying but it doesn’t seem to work, do I need to make changes in this?

Leave a Comment