Tuesday, December 20, 2011

Auto Refresh Report Studio Reports

Automatically refresh Report Studio Reports
Business Case:
Our executive team wanted a performance dashboard that will displayed on a big screen TV in the main conference room. They wanted to make sure that the report displays near real-time data without someone having to manually reload the report.

Environment: IBM Cognos 8.4.1 Report Studio.

Solution:
Our ETL process updates the data warehouse tables every 30 minutes.  I used Javascript to make the reports reload the data every 5 minutes. So the report can be left unattended, and since the report had "Report as of: " right on top, the executives will know when the report was last refreshed.

Code:
Note: The code given below has been tested for IBM Cognos 8.4.1 Report Studio. This code may not work with older versions of Cognos as is. Script was adopted from IBM Knowledge base document  

<script type="text/javascript">
// Licensed Material - Property of IBM
// © Copyright IBM Corp. 2003, 2011
var intval;
var fW = (typeof getFormWarpRequest == "function" ? getFormWarpRequest() : document.forms["formWarpRequest"]);
if ( !fW || fW == undefined)
{

    fW = ( formWarpRequest_THIS_ ? formWarpRequest_THIS_ : formWarpRequest_NS_ );

}
var preFix = "";
if (fW.elements["cv.id"])
{

    preFix = fW.elements["cv.id"].value;

}
var nameSpace = "oCV" + preFix;
if(intval!="")
{

    self.clearInterval(intval);
    intval="";

}

self["RunReportInterval"] = self.setInterval( nameSpace + ".getRV().RunReport()",'600000' );
intval = self["RunReportInterval"];
</script>  


Implementation:
  • Create an HTML item at the end of the page
  • Place the above script inside the HTML item.
  • Report interval (300000 in the code above) is in milliseconds, so 300000 represents 300 seconds or 5 minutes.
  • In the report header or footer, place a data item with report expression "AsOfDate()" 

31 comments:

  1. Hi Sriram:

    Would this code work on Portlets as well or only on reports in report studio? Why can we use the schedules to have the job run every 5 minutes instead of using JS? Are you doing anything different or I am missing the keypoint?

    Cheers!
    -Kavitha

    ReplyDelete
    Replies
    1. Instead of wring such a big script we can achieve this using simple steps given at below link

      http://cognosasksumeet.blogspot.in/search/label/Auto%20Refresh%20Cognos%20Dashboard

      Thanks

      Delete
  2. @Kavitha: Scheduled reports will run in the background and any saved reports will update in the serve, but if I have a report open and I want it to automatically refresh on the screen and keep updating with results, then JS is a good way to go.

    If you know a way to make this work with schedules, please post your method here and I will be happy to add it to my post as an alternative method.

    Sriram.

    ReplyDelete
  3. Hi Sriram,
    Is it possible to refresh the page only once and then clear it out?
    Like after loading the page the page refreshes after 10 seconds (as per the set interval)and then refresh stops.How can we do that?
    I am not an expert in javascript but have a requirement like that.

    Cheers!
    AKS

    ReplyDelete
  4. Hi AKS,

    It is not possible to refresh the report only once. Each time the report refreshes, it will be treated as a fresh run. There is know way to keep track of whether it's the first run or refresh.

    Can you elaborate on why you need to do this? There may be other ways to fulfill your requirements.

    Sriram.

    ReplyDelete
  5. place a data item with report expression "AsOfDate()",,,,i am new to report studio,
    can u explain in detail about, which data item with report expression "AsOfDate()"

    PLEASE

    ReplyDelete
  6. 600 seconds is 10 minutes - FYI

    ReplyDelete
  7. Would this code work on Portlets as well or only on reports in report studio?

    ReplyDelete
    Replies
    1. The code may not work as is in portlets, since we are using cognos viewer functions.

      Delete
  8. Thanks Sriram, its refreshing the report. But My data is not refreshed, as i am using monitor models to collect events and this take quiet time to display on Cognos.

    ReplyDelete
  9. Any way to do this such that my prompt pages don't reappear and just remember my selections?

    ReplyDelete
    Replies
    1. You have to move your prompts to the report page and add default selections.

      Sriram.

      Delete
    2. http://www-01.ibm.com/support/docview.wss?uid=swg21633000

      Delete
  10. Sriram:

    Works splendid. But I have a different need. The result of My report has many rows. What I need to do is that in every refresh, the next page shows up, kind of like de "monitors flights in the airport". Do you know how to do that?

    ReplyDelete
    Replies
    1. Is the number of rows in your report static or can it change drastically? We can do a looping of 20 rows at a time every seconds. I have done this with charts though.. I have a slideshow of charts that change every seconds and the report auto refreshes after 10 minutes so that the chart data can be updated.

      Delete
    2. We can consider the number of rows (per page) a "static number". Let's say 20 rows per page.

      Delete
    3. I meant total number of row in the report, not the rows per page? There must be a way to identify when all the data has been shown and when to start over.

      Delete
    4. Well, the total number of rows can change, not drastically, but can change. In normal situations would be a number between 200 and 300 rows. I estimate that 25 rows can be shown per page.

      Delete
    5. Hi Sriram:

      Do you think you could share your example with charts so I could try to adapt it to my report?

      Delete
  11. Hi Sriram,
    I have a report with 3 pages and I want to automatically refresh and display each page every 1 minute, without manual intervention, i.e. first page is displayed, after 1minute second page is displayed, after 1minute 3rd page is displayed; a minute later first page is refreshed and displayed, etc. How can I achieve this?

    ReplyDelete
  12. Any updates for Cognos 10.2 ? Can't seem to get it to work on this version. Just keeps trying to load page.

    ReplyDelete
    Replies
    1. We recently upgraded our environment to 10.2 and the code works just fine there. Can you email me your code to cognosonsteroids@hotmail.com

      Delete
  13. Sriram,

    Is there any way we can achieve the same in Cognos Workspace. I created the report in RS with the above JS. It works fine standalone. But when I pull this into cognos workspace, it is not refreshing automatically. could you please advise.

    ReplyDelete
    Replies
    1. The DOM object names vary from cognos connection to cognos viewer to workspace. I have to look thru IBM documentation to see if they have a function call for auto refresh in Workspace. As of now, I don't know what it is.

      Delete
    2. Sriram,

      Thanks, When I was using the above script in Workspace there was an error with the getformwarprequest function not available. I changed
      var fW = (typeof getFormWarpRequest == "function" ? getFormWarpRequest() : document.forms["formWarpRequest"]); ... to
      var fW = document.forms["formWarpRequest_THIS_"] ? document.forms["formWarpRequest_THIS_"] : document.forms["formWarpRequest_NS_"];

      But now it is saying RunReport() not available. Do you have any idea?
      Thanks

      Delete
  14. I created a Page with 3 sections, each with a different Cognos 8.4 Report Studio reporting object. All 3 have the above HTML auto-refresh code. But only the right most Page window is refreshing every 5 minutes. What is missing? Does the HTML code not work in a multi-window Page?

    ReplyDelete
    Replies
    1. I have been trying to achieve exacty what you did by accident!



      How did U get just one part of a page to refresh? I have been trying to do that for weeks. :'(

      Delete
    2. The code was written to refresh reports not pages. The cognos DOM object might be different. I am not sure how to make it work for different tabs.

      Delete
  15. hello
    i have a schedueled report who runs every 30 minutes
    my compeny needs this report on dashboard , i would like to reload the report every 30 minutes from the momth we was opened but the result sould be the last run report
    the problem is i need result of the last 30 minutes of complite hour
    like 08:00 ,08:30,09:00
    thank you anat

    ReplyDelete
  16. Instead of wring such a big script we can achieve this using simple steps given at below link

    http://cognosasksumeet.blogspot.in/search/label/Auto%20Refresh%20Cognos%20Dashboard

    Thanks

    ReplyDelete