How to pass a Multi-value Report Parameter (List Box of Type String).<br />
<br />
Most report examples show how to create reports with single value report parameters. The List Box Parameter Type has the ability to allow multiple selections. When using parameters natively in the "Parameter Tab" of a specific Dataset in the UI, you will notice that you cannot create a link to parameters with multiple values, but with only single values. I hope to address a solution here with the solution I provide here (if there are other ways to go about this, I'd love to hear how others are resolving this issue) <br />
<br />
The following example attached uses the example BIRT DB as a datasource, and prompts the user with a multi-value list box as a parameter with a list of all countries. One or more countries can be selected (multiple-selection) or the default value "All Countries" can be selected. The report essentially executes the query: <br />
<br />
"SELECT * from customers where countries IN ( ** comma separated list of values **)" or if "All Countries" is selected, it will simply execute "SELECT * from customers"<br />
<br />
Although there are many ways to do this, the solution I use here is to override the beforeOpen() of the Dataset with this code fragment:
importPackage(Packages.java.io)
countryParamName = "paramCountry" //report parameter
paramCountryLength = reportContext.getParameterValue(countryParamName).length;
this.queryText = "Select * from customers "
this.queryText += " where country IN ("
if (paramCountryLength > 0 ) {
for (i = 0; i < paramCountryLength; i ++ ) {
thisCountry = reportContext.getParameterValue (countryParamName)[i];
if (thisCountry.equals("All Countries")){
this.queryText = "Select * from customers"
return;
}
thisCountryQuote = "'" + thisCountry + "'";
this.queryText += thisCountryQuote;
if ( i != paramCountryLength -1 ) {
this.queryText += ","
}
}
}
this.queryText += " ) "
this.queryText += " ORDER BY country "
<br />
The report was created using BIRT 2.3.1.