### Lesson 9: Creating a parameter-based report

In Lesson 1 of this track we created a page report that contains an order list report tab to show order lists of every month from 2014 to 2015. Now, the sales manager is asking for this same report but with different orders during a specified time. Instead of building a new report about orders in each order date, we will save the page report as a new one and then modify the dataset used by its report to meet the requirements.

- Task 1: Create the parameters
- Task 2: Modify the dataset of the report to use the parameters
- Task 3: Preview and test the report

#### Task 1: Create the parameters

1. Click File > Open to open the report OrderListbyDate.cls created in Lesson 1 in the JinfonetGourmetJava.cat catalog file.
2. Click File > Save As to save the report as OrderListbyDate_Parameter.cls. Then we begin to modify this report instead of the former one.
3. In the Resource View panel, click the <Add Parameter...> item in the Parameters node.

4. In the Create Parameter dialog, enter pStartDate in the Parameter Name field, specify Value Setting as Type-in Parameter and Value Type as DateTime, click the Add button to add a Value List field, enter "May 1, 2015 8:00:00 AM" as the prompting value, and "Please input start date:" as the prompting text. Then click OK.

5. Repeat steps 3 to 4 to create another parameter with the following values:
   - Parameter Name: pEndDate
   - Value Setting: Type-in Parameter
   - Value Type: DateTime
   - Prompting Values: June 1, 2015 8:00:00 AM
   - Prompting Text: Please input end date:

#### Task 2: Modify the dataset of the report to use the parameters

In this task, we will apply the parameters created above to filter the dataset which is used by the report. Then when we view the new report, a message will prompt for us to specify the parameter values. In this way, we can get data that we need.

1. On the Resource View panel toolbar, click the Dataset Filter button.
2. In the Dataset Filter dialog, click the Add Condition button to add a filter line, select ORDER DATE from the field drop-down list, set >= as the operator, then click .
3. In the Expressions dialog, double-click the pStartDate parameter to use it as value of the filter condition. Then close the Expressions dialog.

4. Click Add Condition button to add another filter line. The relationship between the two filters will be And.
5. Specify condition of the newly added filter as follows:

6. Click OK in the dialog to apply the settings.

Parameters can also be used to filter queries to limit their data. However, in this task, we cannot set the filter on the report's query. If we do that, all datasets based on the query will be affected, that is to say, the filter will also be applied to the report created in Lesson 1.

#### Task 3: Preview and test the report

After the steps above, the parameters will take effect when viewing the report by entering values in the Enter Parameter Values dialog.

1. Click the View tab to preview the report.

   JReport recognizes that the query is based on the value of two parameters, and therefore prompts for them as follows:

2. Specify the start date and end date as required in the combo boxes or click the calendar button to select the date.
3. Click the Default button to generate the report output based on the default values for the parameters. The report is displayed as follows, showing information for orders from May 1, 2015 8:00:00 AM to June 1, 2015 8:00:00 AM only:

   Note: If the report does not look correct, you can compare it to the final version of the report provided by JReport. To do so, you will need to save and close this catalog and then open the JinfonetGourmetJava.cat catalog file located at `<install_root>\Demo\Reports\TutorialReports`.

Readers of this report can now input any date to get orders with the time they need by using the parameters.

#### Lesson 9 summary

In this lesson we learned how to use parameters to change the dataset of a report dynamically. Parameters collected at runtime determine which records are selected and ultimately displayed in the report results.

####