Using and submitting report parameters
Use the actuate.Viewer class to run report design and executable files. When a report design or executable runs, actuate.Viewer accepts parameters that modify the report output.
The actuate.Parameter class handles parameters and parameter values. The actuate.Parameter class enables a web page to display and gather parameters from users before processing and downloading a report to the client. Load the actuate.Parameter class with actuate.load( ), as shown in the following code:
actuate.load("parameter");
Load the parameter component to use it later in the page. Call actuate.Parameters functions to prepare a parameters page, display the parameters in the assigned <div> element, and assign the parameters to the viewer object for processing.
Using a parameter component
The actuate.Parameter class is a container for Actuate report parameters. Create an instance of the actuate.Parameter class using JavaScript, as shown in the following code:
var myParameters = new actuate.Parameter( "param1" );
The value of the "param1" parameter is the name value for the <div> element that holds the report parameters display. The page body must contain a <div> element with the param1 id, as shown in the following code:
<div id="param1"></div>
Use setReportName( ) to set the report from which to retrieve parameters, as shown in the following code:
myParameters.setReportName("/public/customerlist.rptdesign");
The setReportName( ) function takes the path and name of a report file
in the repository as the only parameter. In this example, "/public
/customerlist.rptdesign" indicates the Customer List report design in the /public directory.
To download the parameters and display them in a form on the page, call parameter.submit( ), as shown in the following code:
myParameters.submit(processParameters);
The submit( ) function submits all of the asynchronous operations prepared by the calls to parameter functions. The submit function also triggers an AJAX request to download the report parameters to the client. The Actuate web application sends the requested report parameters and the page displays them as a form in the assigned <div> element. The submit( ) function takes a callback function as a parameter, shown above as processParameters.
The following code example calls parameter in the callback function for actuate.initialize( ) to display a parameter:
<div id="param1">
<script type="text/javascript" language="JavaScript"
src="http://127.0.0.1:8080/iportal/jsapi"></script>
 
<script type="text/javascript" language="JavaScript">
function init( ){
actuate.load("viewer");
actuate.load("parameter");
var reqOps = new actuate.RequestOptions( );
actuate.initialize( "http://127.0.0.1:8080/iportal", reqOps,
null, null, displayParams);
}
function displayParams( ) {
param = new actuate.Parameter("param1");
param.setReportName("/Public/BIRT and BIRT Studio Examples/Customer Order History.rptdesign");
param.submit(function ( ) { this.run.style.visibility='visible';});
}function processParameters( ) {
}
</script></div>
The parameter component displays all of the parameters of the report in a form. When the parameters page is larger than the size of the viewer, the viewer provides scroll bars to navigate the parameters page.
To retrieve the parameters, use actuate.Parameter.downloadParameterValues( ). This function takes a callback function as an input parameter. The callback function processes the parameter values, as shown in the following code:
function processParameters( ) {
myParameters.downloadParameterValues(runReport);
}
The downloadParameterValues( ) function requires the callback function to accept an array of parameter name and value pairs. The API formats this array properly for the actuate.Viewer class.
Accessing parameter values from the viewer
The actuate.Viewer.setParameterValues( ) function adds the parameters set by the user to the viewer component. The setParameterValues( ) function takes as an input parameter an object composed of variables whose names correspond to parameter names. The downloadParameterValues( ) function returns a properly formatted object for use with actuate.Viewer.setParameterValues( ). The following code example shows how to call downloadParameterValues( ) and move the parameter name and value array into the viewer with actuate.Viewer.setParameterValues( ):
function runReport(ParameterValues){
var viewer = new actuate.Viewer("viewerpane");
viewer.setReportName("/Public/BIRT and BIRT Studio Examples/Customer Order History.rptdesign");
viewer.setParameterValues(ParameterValues);
viewer.submit( );
}
When the viewer calls submit( ), the client transfers the parameters to the server with the other asynchronous operations for the viewer.
The following code example shows a custom web page that displays parameters and then shows the report in a viewer using those parameters:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/
html;charset=utf-8" />
<title>Viewer With Parameters Page</title>
</head>
<body onload="init( )">
<div id="parampane">
<script type="text/javascript" language="JavaScript"
src="http://127.0.0.1:8080/iportal/jsapi"></script>
<script type="text/javascript" language="JavaScript">
function init( ) {
actuate.load("viewer");
actuate.load("parameter");
var reqOps = new actuate.RequestOptions( );
actuate.initialize( "http://127.0.0.1:8080/iportal", reqOps,
null, null, displayParams);
}
function displayParams( ) {
param = new actuate.Parameter("parampane");
param.setReportName("/Public/BIRT and BIRT StudioExamples/Customer Order History.rptdesign");
param.submit(
function ( ) {this.run.style.visibility = 'visible';});
}
function processParameters( ) {
param.downloadParameterValues(runReport);
}
</script>
</div>
<hr><br />
<input type="button" class="btn" name="run"
value="Run Report" onclick="processParameters( )"
style="visibility: hidden">
 
<div id="viewerpane">
<script type="text/javascript" language="JavaScript" src="http://127.0.0.1:8080/iportal/jsapi"></script>
<script type="text/javascript" language="JavaScript">
function runReport(paramvalues) {
var viewer = new actuate.Viewer("viewerpane");
viewer.setReportName("/Public/BIRT and BIRT StudioExamples/Customer Order History.rptdesign");
viewer.setParameterValues(paramvalues);
viewer.submit( );
}
</script>
</div>
</body>
</html>
The code in the example uses the administrator user credentials and the default report installed with a standard installation of Java Components. The default report is at the following path:
/Public/BIRT and BIRT Studio Examples/Customer Order History.rptdesign