Question

I have some Cognos reports that include custom javascript functions that need to run as soon as the reports load. I haven't been able to find an event that fires when the report is ready, so I've just included the function calls in HTML Items at the bottom of the report. The functions are called as soon as the script tag containing the calls has loaded. The custom functions use jQuery, so I have another HTML Item at the top of the report that imports jQuery.

The problem is that sometimes the functions execute before jQuery has finished loading, causing errors. Inspecting the page source, I see that although the order of the script tags is preserved, they are all placed in the head of the page. There is nothing stopping them from being loaded in parallel, or from executing before the report has finished loading.

The best solution I can think of would be to trigger the function calls from some event after the report has finished loading. Has anyone found an event or set of events that reliably trigger(s) when the report is ready:

  • after loading from its prompt page
  • on drill through from another report
  • when the reprompt button on the page has been clicked?

JQuery's document ready doesn't trigger in any of these situations. <body onload> apparently worked in Cognos 8, but doesn't work in Cognos 10.

Was it helpful?

Solution

Use (document).ready

See this example from IBM

<script type="text/javascript" 
  src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
<script type="text/javascript" 
  src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery-ui.min.js"></script>
<script type="text/javascript">
var j = jQuery.noConflict();
j(document).ready(function()
{
  j('.ShowHideList').hide();
  j('.ShowHideClicker').click(function()
  {
    j(this).next().toggle();
  });
});
</script>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top