Home DevShare Designing BIRT Reports

Reusable library for reloading a report

Share

by mblock

Posted 04 Feb 2009 - 02:39 AM

(0)  (0)   (7090 views)

By downloading this item, you are agreeing to the Terms of Use for the site.

Reusable component that will automatically reload a report on an interval.

Birt Version:-

Attached is a library (and sample report that uses the library) that contains a text item. This text item when included in the beginning of any report will reload the report on an Interval. This interval is a user property in milliseconds. To use this report item just drag the reloadText Text item from the library and set the user property refreshIntervalI (in milliseconds).

Thanks Pierre Tessier, Pierre Richer, and Jason Weathersby for letting me plagerize their code.

Below is the relevant code:


//Build a string that contains all the parameters and their values

var paramsString = "";

var paramDefs = reportContext.getDesignHandle().getAllParameters();

for (i = 0; i < paramDefs.size(); i++ ) {

      var paramDef = paramDefs.get(i);

      if (paramDef.getClass().toString() == "class org.eclipse.birt.report.model.api.ScalarParameterHandle") {

            var paramVal = reportContext.getParameterValue(paramDef.getName())           

            if (paramVal == null || paramVal == "null") {

                  paramVal = "";

            } else if (paramVal.length > 0) {

                  var paramValTmp = "";

                  for (j = 0; j < paramVal.length; j++) {

                        if (paramVal[j] != null && paramVal[j] != "null") {

                              if (j > 0)

                                    paramValTmp += "|";

                              paramValTmp += encodeURIComponent(paramVal[j]);

                        }

                  }

                  paramVal = paramValTmp;

            } else {

                  paramVal = encodeURIComponent(paramVal);

            }                            

            paramsString += "&" + paramDef.getName() + "=" + paramVal;

      }

}

 

//Get the current report name

var reportName = reportContext.getReportRunnable().getReportName();

//Build the URL for re-execution of the report

var targetURL = "executereport.do?__executableName=" + encodeURIComponent(reportName);

targetURL += "&invokeSubmit=true&__wait=wait&__newWindow=false";

targetURL += paramsString;

 

//Set the refresh interval

var refreshInterval = this.getUserProperty("refreshInterval");

 

//Build the script to refresh the current report and get the current viewing options

this.content = "<script type='text/javascript'>";

this.content += "function getQueryParam(param) {";

this.content += "var loc = location.href;";

this.content += "var ind = loc.indexOf('&' + param + '=');";

this.content += "if (ind <= 0) ind = loc.indexOf('?' + param + '=');";

this.content += "if (ind > 0) {";

this.content += "var indx = loc.indexOf('&', ind + 1);";

this.content += "if (indx > 0) return '&' + loc.substring(ind + 1, indx);";

this.content += "else return '&' + loc.substring(ind + 1);";

this.content += "}";

this.content += "return ';";

this.content += "}";

this.content += "function refreshReport() {";

this.content += "var url = '" + targetURL + "';";

this.content += "url += getQueryParam('__format');";

this.content += "url += getQueryParam('__svg');";

this.content += "url += getQueryParam('__locale');";

this.content += "location.href = url;";

this.content += "}";

this.content += "timer = setTimeout('refreshReport()', " + refreshInterval + ");";

this.content += "</script>";

 

 

 

Download (4 KB)

By downloading this item, you are agreeing to the Terms of Use for the site.



Virgil

Posted: 04 Feb 2009 - 01:38 PM

Thanks Mica... for anyone else looking for this code in the download, you will find it by opening the library, selecting the text element from the Report Outline, and then the Script tab.
 
Filter More