Using an agent, standard activities, and a Connect File rule, your application can create, once each night, a snapshot Portable Document Format (PDF) file containing list view report output.
The approach can be generalized to produce a set of daily, weekly, or monthly reports.
In addition to the list view report, you need to construct three rules:
- An activity that runs a list view rule and captures the report output as a PDF document in a parameter. The PDF document is not sent to a user browser session.
- A Connect File rule that writes the PDF document to the file system as a PDF file.
- An Agent rule that causes the activity to run once each night.
Note: This approach works for list view reports, not for summary view reports or for charts. Interactive charts contain Adobe Flash output, which is not supported by Adobe's PDF file format.
Step 1: Identify the list view rule
You may execute any list view report that does not require users to supply prompt values for report selection criteria. Note the RuleSet and version for the list view rule. If the selection criteria involve dates, consider using symbolic dates.
In this example, the list view report MyCo-Emerald-Task.ShowYesterday.ALL reports on work objects that were created yesterday but remain open.
This report shows a few basic facts about each selected open work object:
Step 2: Build the Connect File rule
A Connect File rule identifies the directory on the Process Commander server that is to contain the output file, and the name of the output file. Set the Applies To key part of the Connect File rule to Code-Pega-eForm.
In this example, the output file name uses the Global Resource Setting syntax =pagename.propertyname, so that the output file name can vary from execution to execution. (As shown below, the property pyLabel on page PDFPage contains the run date.)
Save. You can click the Test Connectivity button to confirm that the destination directory — D:/temp in this example — exists.
Step 3: Build the activity
Create an activity. In this example, the Applies To key part of the activity is the same as the Applies To key part of the list view rule.
On the Security tab, check the May Start? box and clear the Authenticate? box. Set the Activity Type to Activity.
On the Pages & Classes tab, enter a page name (such as PDFPage) of class Code-Pega-eForm.
Complete the Steps tab. In activity step 1, set the value of five parameters for the standard activity Rule-Obj-Report-.getReadOnlyReportDisplay. The correct spelling of the fourth parameter is ViewOwner (not VewOwner, which appears on the Parameter tab of that activity).
In activity step 2, call the standard activity Rule-Obj-Report-.getReadOnlyReportDisplay. This activity executes the report and saves the resulting HTML code into an output parameter named pyViewData.
In activity step 3, use a Property-Set method to copy the parameter pyViewData into parameter Markup.
In activity step 4, call the standard activity @baseclass.HTMLtoPDF. This activity accepts as input the HTML code in param.Markup and returns a the PDF document in a Java byte array parameter named PDFDocument.
In activity step 5, create an empty page of class Code-Pega-EForm.
In activity step 6, copy the Java byte array in param.PDFDocument into a Java Object property pyEForm, on the new page.
In this example, the output file name in property .pyLabel is formed by concatenating the current date, the list view middle key part, and the file type suffix ".PDF". For example, on April 14, 2009 the report file is named 20090414OpenYesterday.PDF and contains data about work objects created on April 13.
In the final step 7, the activity calls the Connect-File method to write out the file.
Save the Activity form. At this point, you can test the activity.
Step 4: Build the agent
Create an agents rule named for the RuleSet.
- On the Schedule tab, reference the activity and enter a recurring schedule, such as one minute after midnight.
- On the Recurrence window, type the time zone carefully, using one of the time zone codes available from the Advanced tab of the Operator ID form.
- On the Security tab, choose an access group that ensures the agent has the ability to find and execute all the rules mentioned in the article.
Step 5: Enable and test
On the Agents form, enable the activity and the Agency-Wide settings. Save the Agents form. After approximately 10 minutes, your system will contain one agent schedule instance, derived from the agent rule, with a node hash as key part . In a multinode clustered system, open and disable the agent on all but one node.
Use the System Management Application to verify that the agent executes as scheduled. Note that the Recurrence setting defines a "not-before" time of 12:01 AM. The activity may run at 12:01:00, or 12:03:59, or even later if the node is is busy around midnight. The agent activity doesnot run at exactly the same time each morning. However, it only runs once.
Click the PDF file to review report output.
These possible enhancements can make the capability more robust and general-purpose:
- The activity can be adjusted to run any list view report in the Applies To class, based on a parameter.
- The activity does not check the status value @baseclass.pyStatusValue for the success value "Good" from the Connect File execution. As a good practice, this examine this value and write a log message when the value is not "Good".
- The activity can be enhanced to run multiple reports (in sequence, one at a time) and create multiple output files.
- Using the Connect-FTP method, you can copy the output PDF files files from the Process Commander server to a remote server.
- How to write a file to the local file system using a file connector
- How to create an agent
- How to reduce maintenance of service rules and listeners with Global Resource Settings
- How to use symbolic dates in report selection criteria
- How to unit test activities with the Automated Testing feature
- Working with PDF forms and documents (V5.1)
- How to copy files to remote systems using File Transfer Protocol (FTP)