Consider a scenario where we want to download recently added table data from the screen into a CSV format for analysis. Today, we will explore how to accomplish this in Pega.
An existing out-of-the-box activity named "pxConvertResultsToCSV" is available in the @baseclass, and you can utilize it without the need to create it from the ground up. The following example illustrates a sample screen: when the button is clicked, the Page List data on the screen is downloaded as a CSV file to the end user's local machine.
1.To begin, establish a Page List property. In this instance, I defined a Data class, "MyCo-Data-Item," and subsequently generated a Page List named "ItemList" in the Work class, referencing the Item class.
2.Position a table that references the Page List, and configure it to be inline-editable, allowing the addition of records directly from the screen. Additionally, position a button in close proximity to the table.
3.Configure the button by adding an "Open URL in Window" action for the Click event and specify an out-of-the-box activity named "pxConvertResultsToCSV." Ensure that "Use Page" is checked. The minimum parameters to set include:
CSVPropertyTypes: The properties you wish to output, separated by commas. Avoid inserting spaces between them (as it may result in empty data).
Note: It's not necessary to specify all properties, only the ones you want to include in the CSV. Additionally, you have the flexibility to change their order as desired.
PageListProperty: Specify the name of the Page List property to be read in the primary page. In this example, set it to "ItemList."
4.That concludes the setup. Test the functionality to ensure that a separate window pops up, and the CSV file is successfully downloaded to your local machine.
Within the Cosmos theme, the results page is loaded onto the DCSPA_UserPortal/ACPRIMARY_0 thread. Within this thread, automatically check the name of the top page generated by the system. In this instance, it is "pgRepPgSubSectionDataEntryBB.pxResults."
Input "pgRepPgSubSectionDataEntryBB.pxResults" into the PageListProperty parameter. Ensure it is enclosed in double quotes; otherwise, it may fail at runtime.
Now, proceed to test by displaying the Page List data constructed by the Report Definition, and then click the download button.
Despite the default page size in the Report Definition being set to 50, this value is not utilized on the screen. The page size on the screen is configured within the Table settings. In this instance, I have configured it to be 5.
With these settings, the system shows 5 rows per page on the screen, not 50. When you download a CSV file, the file only contains the first page, which consists of 5 rows. This is not the intended outcome.
Now, configure the new activity. In the first step, invoke Rule-Obj-Report-Definition.pxRetrieveReportData. You can use the same Report Definition. Specify a page for pyPageName; in this example, I named it "tempPage." In the second step, invoke pxConvertResultsToCSV and pass "tempPage.pxResults" for PageListProperty.
Comments
Post a Comment