Jump to: navigation, search

Null Report Parameter Passed to Data Set (BIRT)

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

Introduction

This example illustrates handling a null report parameter before using it in a data set parameter.

BIRT Version Compatibility

This example was built and tested with BIRT 2.1.2.

Example Files

Example Report Zipped

Description

BIRT Supports Report Parameters and Dataset Parameters. A Report parameter can be setup to accept null values. JDBC Dataset parameters are created when using the ? within the SQL Editor. The dataset parameter is then linked to a report parameter in the dataset editor (Parameters entry). This works fine unless the parameter is null. To deal with this problem you can tie your report parameter to the dataset in the beforeOpen event handler for the dataset. In the attached example the query that is used is as follows:

select *
from orderdetails
where CLASSICMODELS.ORDERDETAILS.ORDERNUMBER is NULL 

So the default query is looking for null order numbers. The report also has a parameter that has the allow null check box checked. In the beforeOpen script for the dataset the following is entered.

if (params["NewParameter"].value){
           this.queryText = "select * from orderdetails where CLASSICMODELS.ORDERDETAILS.ORDERNUMBER =" + params["NewParameter"];
}

If the report parameter is null this code will not be executed. If the parameter is not null the query is altered to append the parameter to the where clause.

for more complex query it's not a good solution