## Lesson 5: Scheduling report sets

In Lesson 3 of this trail we ran published report sets by using the Run command in the JReport Console page. Report sets run in this way are on-demand report sets. By contrast, JReport Enterprise Server allows report sets to be scheduled, that is, automatically run at one or more designated dates and times.

Scheduled report sets can greatly improve the performance of the reporting service in an organization. For example, report sets can be run during low network traffic times. Scheduled report sets can capture a time period exactly, for example the last day of the quarter.

A scheduled report set is not delivered to an end user in the same way an on-demand report set is. There are six destinations for scheduled report sets:

- Publish to Versioning System
- Publish to File System
- Publish to E-mail
- Publish to Printer
- Publish to Fax
- Publish to FTP

In this lesson, we explore three of these:

- Example 1: Publish a report set to the versioning system
- Example 2: Publish a report set to the file system
- Example 3: Publish a report set to the printer

### Example 1: Publish a report set to the versioning system

The built-in JReport Enterprise Server Versioning System is a virtual file system maintained by JReport Enterprise Server.

In this lesson we will set up a schedule to run a report set immediately and specify that the generated result be kept for 30 days. Even though we run the task immediately, the result is scheduled to run through the JReport Enterprise Server scheduling system.

Another advantage of scheduling a report set is that it can be saved in the versioning system while normally on-demand report sets will not be saved unless explicitly saved by the user.

1. On the JReport Console > Reports page, click the My Reports link.

   You can access the JReport Console page by pointing a web browser to http://localhost:8888.

2. Click the JinfonetGourmetJava link.
3. Select the row with the OrderListbyDate_Parameter.cls report set, right-click in the row and then select Schedule from the shortcut menu.

   The General tab of the Schedule page appears. The report OrderDetails is selected by default to be scheduled.

4. Enter ToVersion in the Schedule Name text field.
5. If desired, you can enter new parameter values or keep the default values.
6. Expand the Report Set Info section. From both the Report Set Version and Catalog Version drop-down lists, choose the most recent report set and catalog versions.
7. Expand the Advanced section, and select Use the default DB user and password defined in catalog option if it is not selected.
8. Click Next to go to the Publish tab.
9. In the Publish tab, click To Version and then check Publish to Versioning System.

   The publishing options appear.

10. Select the DHTML format, check the Result Auto-delete checkbox and set Result Expires in 30 Days.
11. Switch to the Conditions tab to continue.
12. In the Time sub tab, choose Run this task immediately from the Time Type drop-down list. The Time Zone field should represent your current time zone.
13. Click Finish to submit the task.

You can monitor the status of the report set by viewing the My Tasks page (to access this page, click My Tasks on the system toolbar). Report sets that are running are listed in the Running tab; when complete they will be moved to the Completed tab. Report sets which are scheduled but have not yet run are listed in the Scheduled tab.

Once you see that the report set you scheduled is listed in the Completed tab, you can view the report set results as follows:

1. Select the row that the report set is in, right-click in the row and select Version from the shortcut menu.

2. On the Report Set Result Versions tab, click the DHTML link in the Result column. The full DHTML report set is displayed.

### Example 2: Publish a report set to the file system

In this lesson we set up a schedule to output a weekly sales report to the file system. The report is run every Sunday night so it will be available first thing on Monday morning.

1. On the JReport Console > Reports page, go to the My Reports > JinfonetGourmetJava folder.
2. Select the row with the CustomerContactCard.cls report set, right-click in the row and select Schedule from the shortcut menu.
3. In the General tab, enter ToPDF as the schedule name and select the report CustomerInformation in the report set.
4. Click the Publish > To Disk tab, and then check Publish to Disk.
5. Check PDF. The PDF options appear.

6. From the drop-down list, choose Publish to Server Resource Tree and directly below the list enter /CustomerContactCard.pdf.

   This publishes the report in the server resource tree under the name /CustomerContactCard.pdf.

   The Server Disk Path is set by default to `<install_root>\jreports` thus if we want to place the output file in the `<install_root>\jreports` folder the path must start with a /. Alternatively we could enter a full path on the server if we wanted the file to be created outside of the server resource tree.

7. Select the Conditions tab to specify the time when the task is to be performed.
8. In the Time sub-tab, choose Run this task periodically from the Time Type drop-down list. Select Weekly from the Date drop-down list and define to repeat every one week on Sunday. Select At from the Time drop-down list and specify the time as 9:00 PM.

   Although we won't use it in this lesson, the Notification tab allows you to specify e-mail notifications to be sent automatically when the report is finished or if it was unable to complete successfully.

9. Click Finish to submit the scheduled report request.

Since it isn't practical to wait until Sunday evening to see the report in our lesson, we're going to cheat a bit and request an early version of the report.

1. Click My Tasks on the system toolbar. The report we requested above should appear as a scheduled task.

2. Select the task and click Run on the task bar of the My Tasks page to immediately schedule the report.

   You can find the report using Windows Explorer in `<install_root>\jreports\CustomerContactCard.pdf`. By default, <install_root> is `C:\JReport\Server`, however a different directory may have been specified at install time.

### Example 3: Publish a report set to the printer

In this lesson we set up a schedule to output a form letter report to the printer on a monthly basis. The form letter is to be sent to delinquent customers.

1. On the JReport Console > Reports page, go to the My Reports > JinfonetGourmetJava folder.
2. Select the row with the ProductSalesAnalysis.cls report set, right-click in the row and select Schedule from the shortcut menu.
3. In the General tab, enter ToPrinter as the schedule name and select the report ProductSales in the report set.
4. Click the Publish > To Printer tab, then check Publish to Printer.
5. Fill out the tab according to your requirements and the printer settings.

6. Click the Conditions tab, and then click the Time sub tab to specify the time when the task is to be performed.
7. From the Time Type drop-down list, choose Run this task periodically, select Monthly from the Date drop-down list and select to run The 1st Day of every 1 month(s) and 7:00AM as the time.
8. Click Finish to enter the scheduled report request.
9. Click My Tasks on the system toolbar. When the task is running, you can see the record of this task in the Running table and it will be put into the Completed table when the task is finished by the server. You probably want to go to the Scheduled tab and delete this entry so it does not print to your printer every month!
10. Exit the JReport Console page by clicking the Logout link.