Skip to main content

Attaching Excel file to email

 

Step-by-Step Guide for Exporting Data Page List to Excel and Sending as Email Attachment.

This article presents a systematic configuration process for exporting a data page list to an Excel file and subsequently dispatching the Excel file as an email attachment. The demonstration herein was carried out using Pega Platform 8.8.2.

Step 1 – Set an output Excel file name.

  • Notice the file extension (.xlsx) used.


Step 2 – Generate an Excel file by using an OOTB pxGenerateExcelFile activity.
  • Do NOT select the DownloadFile checkbox.

  • Refer to this article to learn more about how to export a data page list to an Excel file.

Step 3 – Set an output Excel file location.
  • System automatically saves the output Excel file to pxProcess.pxServiceExportPath.


Step 4 – Generate an output Excel file stream byte.  This Java step converts the Excel output file to a byte stream.

  • A local variable (strFileData, String) must be defined in the Parameters tab of the activity.

  • A local variable (attach, Boolean) must be defined in the Parameters tab of the activity.

  • Open the attached file (Step4_Java_Source_Code.txt) to copy the source code, and paste to your Java step.


Step 5 – Set the attachment properties.

  • Under ‘Pages & Classes’ of activity, define a page name (Attachment) with Class (Embed-EmailAttachment).

  • Note that .pyData property is set with local.strFileData which contains the Excel file stream byte generated by the previous Java step.


Step 6 – Add the Attachment page to AttachmentList page.

  • Under ‘Pages & Classes’ of activity, define a page name (AttachmentList) with Class (Data-EmailAttachments).

  • CopyInto = AttachmentList.pyAttachments(1)

    • To add another attachment, copy it to AttachmentList.pyAttachments(2) and so on..

Step 7 – Open an Email Account instance, which will be used to send an email with attachment.

  • Under ‘Pages & Classes’ of activity, define a page name (Email) with Class (Data-EmailAccount).

For this demo, a Gmail account was used as Sender.

Step 8 – Set the email parameters.

Step 9 – Call an OOTB SendEmailNotification activity to send out an email with attachment.


Step 10 – Clean up temporary pages.


Click “Run” to test the activity.  It should send an email with an Excel attachment.


Happy Learning :) :)


Comments

Popular posts from this blog

Understanding the Lock Mechanism in Pega

Now, let's delve into the Pega lock mechanism. To begin, Pega employs both database-level locks, which are of shorter durations (usually in milliseconds), and Pega-level locks, which extend over more extended periods (determined by user operations, often a few minutes). While you have the option to disable Pega-level locks using the Optimistic locking strategy (discussed later), database-level locks cannot be turned off; they are an integral part of the infrastructure layer. Moving forward, I'll elaborate on Pega-level locks. 1. Fundamentals of Pega-Level Locks When an individual initiates an assignment, the system transitions the state to "Perform" mode and acquires a lock. This lock data is then added to the "PR_SYS_LOCKS" table in the database, where it is systematically managed. Throughout this phase, no other user can access the same assignment. Upon the user's submission or cancellation of the assignment, the state shifts to "Review" mode...

How to set up JFrog Artifactory as a Repository in Pega.

Before delving into the topic, let's gain some understanding of what a repository is........... What is a repository? A repository is a centralized storage location where data, files, documents, or other digital assets are stored and managed. It serves as a single source of truth for organizing, versioning, and accessing these assets.  In the context of software development, a repository typically refers to a version control system, where developers store and manage source code, configuration files, documentation, and other project-related files. Version control systems like Git, Subversion (SVN), and Mercurial are commonly used repositories in software development. In addition to version control systems, repositories can also refer to databases, file systems, content management systems (CMS), or any other structured storage system used to manage digital assets. Overall, a repository provides a structured and organized way to store and manage digital assets, facilitating collaborat...

Building a CSV File Download Function from a Page List

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 ...