Adding Parameters to the Report
Many reports will require one or more parameters that help the user to filter the results they get back from the report.
For example, records between a certain date range or a text field in the record that matches a value set by the user when running the report. The following report illustrates various ways of setting report parameters.
Adding a Date Type Parameter
The following process describes how to apply date filtering to a new or existing report to restrict the data results to a specific point in time (or date range). For example, you may wish to enable the user to select a date or date range in which to display results - when the user selects the report they will be presented with date fields to choose any date values they want to filter the report on.
- Open the Customer List report. (A fast way to reopen a report is to click on File → Open Recent File then select the Customer List report)
Add a new parameter to represent the Date value we want to search for. Right-click on Parameters in the Report Inspector window then select Add Parameter, this will create a new parameter named
parameter1
. We'll use this to set the date from which records are to be selected.Click the
parameter1
at the Report Inspector (left panel), this will show the properties at the right panel under Properties, set the Name of the parameter asP_DATEFROM
, and change the Parameter Class to java.lang.Date. This will ensure the date picker control appears to help the user select their date- We have to update the SQL statement in the report to include this parameter in the WHERE clause that filters the Date field. Right-click on the name of the report and select Edit Query to edit the SQL Query for this report
- Write the WHERE sentence
WHERE VSCL.CREATEDDATE >= $P{P_DATEFROM}
. You can also drag the parameter to the editor. - Now run a Preview to test the new parameter in your report.You should be presented with date picker controls for each of your parameters
Update AppBase importing this new version using the steps in the article Adding Parameters to the Report
Adding a String Parameter
- Open the Customer List report. (A fast way to reopen a report is to click on File → Open Recent File then select the Customer List report)
Add a new parameter to represent the Priority value we want to search for. Right-click on Parameters in the Report Inspector window then select Add Parameter, this will create a new parameter named
parameter1
. We'll use this to set the date from which records are to be selected.- Click the
parameter1
at the Report Inspector (left panel), this will show the properties at the right panel under Properties, set the Name of the parameter asP_PRIORITY
, and change the Parameter Class to java.lang.String. - We have to update the SQL statement in the report to include this parameter in the WHERE clause that filters the Priority field. Right-click on the name of the report and select Edit Query to edit the SQL Query for this report.
- Add to the WHERE sentence
AND UPPER(VSCL.PRIORITY_NAME) LIKE UPPER($P{P_PRIORITY})
. You can also drag the parameter to the editor. Run a Preview.
(Note that when you preview this report in iReport, it has no awareness of the parameter you have created in your Solution so you will have to directly type in your status value to restrict what records you get back).- Update AppBase importing this new version using the steps in the article Adding Parameters to the Report
Related Articles
- Adding Attribute Types to Reports
- Building a New iReport
- Connect to a Solution Database
- Wiki - Using Report Parameters