Dynamic JavaScript Loader

Options
rmurphy
edited February 11, 2022 in Analytics #1
It is quite common to want to include JavaScript in your BIRT report to be executed client side. BIRT allows you to include Script tags using the Text report item, but does not allow for inclusion of source JavaScript files.<br />
<br />
This report library includes a Text control that can be included in a report along report variables to dynamically load scripts source files into your BIRT report. The library leverages head.js (http://headjs.com/) to handle the resource loading.<br />
<br />
To load a script, include the Text control from the library in your report along with a report variable in your report design with a name that begins with Script_. After the underscore, the name can be anything (i.e. Script_jquery). You can include as many scripts as needed by creating new Script_ report variables. If you include multiple scripts with Script_ variables, they will be loaded in parallel.<br />
<br />
After all scripts defined by the Script_ report variables have been loaded, the function defined by the Callback report variable will be called. In addition to allow you to use the newly loaded script, it is also how you can load dependant libraries. For example, OpenStreetMaps JavaScript relies on the OpenLayers JavaScript source being loaded. In this instance you can include OpenLayers with a Script_ (i.e. Script_openLayers) and include a JavaScript function in a text element in your BIRT report to be called as the callback. This function would make a uses the head() function from head.js to the load the OpenStreetMaps JavaScript.<br />
<br />
Tips:
    <br />
  • Use external browsers when viewing/previewing in the BIRT Designer.<br />
  • Be mindful of quotes used in your Script_ variable value. The library uses single quotes (') to wrap the string value of the Script_ variable value. If you need quotes in your string, use escaped double quotes (\"). See the Treemap.rptdesign example.<br />
  • Simple Example.rptdesign defines a Script_ variable that is looking for the included SimpleExample.js file at http://localhost/SimpleExample.js<br />
Tested with, and samples included for, Eclipse BIRT 3.7.2 and 4.2.1 and Actuate BIRT 11 SP4.