Getting a parameter value
A script gets the value of a report parameter by passing the name of the parameter to the getParameterValue( ) method of the reportContext object. The following statement gets the value of the UserID parameter:
userID = reportContext.getParameterValue( "UserID" );
You can also retrieve parameter values using the BIRT global variable, params, in a statement that has the following syntax:
userID = params["UserID"].value;
Params logs parameter value settings when a report document is generated. Changing the value of the params global variable does not set a parameter value. You cannot change a parameter value with a script after iHub generates a report document. BIRT also supports dynamic parameters that allow selecting multiple values. Access these parameters using the following syntaxes:
reportContext.getParameterValue( "MultiParm" )[0];
params["MultiParm"].value[0];
The previous statements retrieve the first value of a multivalued parameter. Determine the number of selected values by using the following syntaxes:
reportContext.getParameterValue( "MultiParm" ).length;
params["MultiParm"].value.length;
You can use these features when implementing a beforeOpen event handler to apply an IN clause to a query, as shown in Listing 37‑19.
Listing 37‑19 Accessing multiple parameter values in beforeOpen
var parmcount = params["parmorders"].value.length
var whereclause = "";
if( parmcount > 0 ){
whereclause = " where customernumber in ( ";
}
for( i=0; i < parmcount; i++ ){
if( i == 0 ){
whereclause = whereclause + params["parmorders"].value[i];
 
}else{
whereclause = whereclause + " , " + params["parmorders"].value[i];
}
}
if( parmcount > 0 ){
this.queryText = this.queryText + whereclause + " ) ";
}
Data sets also have parameters. These parameters affect the specific data set. Typically, data set parameters are linked to a report parameter or bound to an outer table column value when the data set is bound to a nested table. Data set scripts support getting and setting values for parameters. Set the value of the parameter before the data set runs in the beforeOpen of the data set, as shown in Listing 37‑20.
Listing 37‑20 Setting a data set parameter value in beforeOpen
//set input parameter
inputParams["alpha"] = 5;
//or
this.setInputParameterValue("alpha", 5);
You can get the value by referencing the inputParams array or using the this.getInputParameterValue method.