Nested Tables using two Scripted data sets (BIRT)

From Eclipsepedia

Jump to: navigation, search

< To: Report Developer Examples (BIRT)
This example is Bugzilla ID 191565. If you would like to contribute an example see the example contribution guidelines.



Scripted data sources are an effective way to retrieve data when no specific driver is available or your data resides in POJOs. In this example we illustrate nesting two tables that use scripted data sets.

BIRT Version Compatibility

This example was built and tested with BIRT 2.1.2.

Example Files

Example Report


This first thing we do in this example is create the sample data to use. This is done by adding the following to the beforeFactory event handler.

importPackage( );
importPackage( );

var outerMap = new Hashtable();
var innerMap = new Hashtable();

for ( i=0; i<10; i++ ){
    var mystring = "Outerrow_" + i;
    var myinnerstring = "Innerrow_" + i;
	outerMap.put(i, mystring);
	innerMap.put( mystring, myinnerstring );
reportContext.setPersistentGlobalVariable("outerMap", outerMap);
reportContext.setPersistentGlobalVariable("innerMap", innerMap);

As you can see we are loading two Maps, an outer and inner. The outer map is keyed 0-9 and its value is Outerrow_i, The outer row value is then used to key the inner map and its value is set to Innerrow_i. The reason this data is created this way is to illustrate using data set parameters when accessing the inner map.

Next add a scripted data source and create two scripted data sets. The outer data set will have one column of string type named outtercol. Its open and fetch are shown below:


hMap = reportContext.getPersistentGlobalVariable("outerMap");
iter = hMap.entrySet().iterator();

Just get the outer map and setup an interator


if( iter.hasNext() ){
    myObject =;
    row["outtercol"] = myObject.getValue().toString(); 
    return true;
    return false;

Just iterate over the outer map and set the column to the map value.

This data set can then be bound to a table.

Next create the inner data set, which should have one column of string type and a data set input parameter. Its open and fetch are shown below:


i = 0;
jj  = inputParams["innerparm"];

retrieve the input parmaeter and set the jj var to its value. We only want the inner loop to run once per outer so we use the i var to control this.


iMap = reportContext.getPersistentGlobalVariable("innerMap");
inObj = iMap.get(jj);
if( i > 0 )return false;

if( inObj != null ){
    row["innercol"] = inObj.toString();
return true;

Get the inner map and look for the key from the input parameter, which should be the value of the outer map.

Next add a column to the existing table and drag the new inner table into the detail row of the new outer table column.

It is important to remember to link the inner table data set parameter to the outer table row value in the binding tab. Use the Dataset Parameter Binding button on the Binding tab of the inner table.


Please enter comments below by selecting the edit icon to the right. You will need a Bugzilla account to add comments.