Calling client and external JavaScript functions
You can call JavaScript in a variety of ways. Within a report, you do not have to rely solely on the server-side events. You can run client scripts within a report easily with the clientScript selection on the event menu. You can also use external JavaScript files from the resource folder.
Using client-side JavaScript
As of version 4.3, calls to client-side JavaScript libraries within a report can be achieved using a simplified approach. You can access your data sources through a BIRT report design, then provide a data set to the client using a variable or file.
How to use client-side JavaScript libraries
1 In the report design editor, click on an empty area of the report.
2 Select Script, then choose clientScripts, as shown in Figure 37‑19.
Figure 23-9 Selecting the report design in OutlineFigure 23-9 Selecting the report design in Outline
Figure 37‑19 Selecting clientScripts for a report
3 Add code for a head.js script that contains library file references and callback functions. An example head.js is shown in Listing 37‑27.
Listing 37‑27 Example of head.js clientScript code
head.js (
function ()
alert("Loaded all JS libraries");
4 Return to the Layout view and add a text item from the palette.
5 Select HTML as the text item type and add your client code. An example is shown in Figure 37‑20.
Figure 23-9 Selecting the report design in OutlineFigure 23-9 Selecting the report design in Outline
Figure 37‑20 Entering the client-side script
The client script can access the full HTML DOM and use any of the functions of the JavaScript library. You can pass variables to the client, including arrays representing fetched rows of data using <value-of> tagging.
Referencing JavaScript from the resource folder
In addition to executing JavaScript within a report, BIRT provides the option to use external JavaScript files located in the resource folder. Use the Resources view and the property editor to associate these files with the selected report. For example, an external JavaScript file has the following content:
function getMyValue( ){
return "This is a test of the add js button";
If this file is located in the resource folder, a report developer can select the resources tab of the property editor and add the JavaScript file to the report. The JavaScript file is not imported, but is referenced in the report. After making this association, the developer can call getMyValue( ) in any BIRT expression or any of the event handler scripts.