Sometimes you need report results inside an activity, for example to count open cases before a decision or to loop over the rows and update them. Pega lets an activity run a Report Definition and put the rows on the clipboard for you to use.
The standard way
Use a Call step that runs the standard activity Rule-Obj-Report-Definition.pxRetrieveReportData. Before the call, set the parameters it needs using a Property-Set step:
| Parameter | Meaning |
|---|---|
Param.pyReportName | The name of the Report Definition rule to run |
Param.pyReportClass | The class the Report Definition belongs to |
Param.pyPageName | The name of the page where the results will be placed |
Passing your own values to the report
If the Report Definition has its own parameters, for example a customer ID that filters the rows, set those in the same Property-Set step before the call. The report reads them when it runs, so the same rule can serve many different filters.
A worked example
A bank activity must find all overdue loans for one branch.
- Property-Set:
Param.pyReportName=OverdueLoans,Param.pyReportClass=Bank-Work-Loan,Param.pyPageName=OverdueResults, and the report parameterParam.BranchCode=.BranchCode. - Call
Rule-Obj-Report-Definition.pxRetrieveReportData. - Loop over the results list on
OverdueResultsand send a reminder for each row. - Page-Remove
OverdueResultsto clear the clipboard.
A cleaner option: data pages
For reading data on a screen, a list data page with a Report Definition as its source is usually better. It caches the result, takes parameters, and needs no activity. Reach for the activity approach when you need to process the rows in a loop or run the report as one step of a longer procedure.
Tips
- Always limit the rows. A report with no filter on a big table can return thousands of rows into memory.
- Check the results page name for typos, because a wrong name gives an empty list with no error.
- Test with the Tracer to see the SQL that ran.
Troubleshooting: the report returns no rows
- Check that
Param.pyReportClassis the class the Report Definition is defined in, not a parent or child class. - Check the spelling of every parameter name. A wrong name is ignored silently, so the filter does not apply the way you expect.
- Confirm the results page name matches in both the Property-Set step and the loop that reads it.
- Run the activity with the Tracer open and look at the SQL that was generated, then run that query against the database to compare.
- Make sure the operator has access to the report class, because a user without rights may get no data.
Common questions
Should I use an activity or a data page to read a report?
For displaying data on a screen, use a list data page sourced from the Report Definition. Use the activity approach when you must process the rows one by one or run the report as a step in a longer procedure.
How do I avoid loading too many rows?
Add filter conditions in the Report Definition and set a sensible maximum number of rows. Never run an unfiltered report against a large table inside an activity.
Related: Remove duplicates in a Report Definition and the Report Definition label.
No comments:
Post a Comment