Question

How to attach an excel or a pdf file to an email automatically

Hi All,

Good Morning, i have one scenario where we have few results in a page list and need to import them into an excel and need to attach it as an attachment to an email.

Note: input results to the excel file are coming from db using RDB-List.

Can you please help me understand or give me some reference how i can achieve this.

Thanks

Venkatesh G.

**Moderation Team has archived post**

This post has been archived for educational purposes. Contents and links will no longer be updated. If you have the same/similar question, please write a new post.

Correct Answer
January 3, 2016 - 1:42am

Hi

I have used property-set-html and set the results stream into a html stream and used the same reference in pyData property for pyAttachment page.

Thanks

Venkatesh G

Comments

Keep up to date on this post and subscribe to comments

December 29, 2015 - 10:33pm

If you are on Pega 7.1.7 or above, you can reuse or use as reference, this activity @baseclass.pxConvertResultsToCSV to convert page list to CSV format. You can then leverage @baseclass.SendEmailNotification activity passing an AttachmentPage of class Data-EmailAttachments by copying the CSV data on to the AttachmentPage.

December 30, 2015 - 11:33pm
Response to PraneethPurighalla

Hi Praneeth Purighalla,

Thanks for the quick response. Currently i am using MSOGenerateExcelFile to generate the excel file.

Note: i don't have any workobject here, my scenario is like batch process where i need to get some results from db and export them to excel and send it to people as attachment on recurring basis like 4 times in a day.

.

<<<You can then leverage @baseclass.SendEmailNotification activity passing an AttachmentPage of class Data-EmailAttachments by copying the CSV data on to the AttachmentPage

Can you please explain in detail or give me any reference.

I have tried below approach.

1) Call  MSOGenerateExcelFile with steppage as AttachmentPage(of class Data-EmailAttachments) but i am not seeing attachment content in that page.

2)Use the java method to write the following piece of code.

If i hardcode the AttachementPage.pyAttachments(1).pyData="test" in the attachmentpage i am getting the attachment.

------------Start of code-----------------------------ClipboardPage page_EmbedAttachment = null,page_AttachmentPage = tools.findPage("AttachmentPage");

ClipboardProperty prop_pyAttachment = null;

try {

prop_pyAttachment = page_AttachmentPage.getProperty(".pyAttachments(<append>)");page_EmbedAttachment = prop_pyAttachment.getPageValue();

page_EmbedAttachment.putString(".pyData",datatoattach);// datatoattach should contain a Base 64 Encoding of the entire attchment from excel filepage_EmbedAttachment.putString(".pyName","XYZ.xls");page_EmbedAttachment.putString(".pyDecode","true");page_EmbedAttachment.putString(".pyRemoveXML","false");

} catch (Exception e) {

tools.getPrimaryPage().addMessage( e.getMessage() );

}

--------------End of code ----------------------------------

3)Call SendEmailNotification and send "AttachmentPage" in the parameter ReferencePage.

**Now my question is how can i copy that CSV data into the AttachmentPage ?

Thanks

Venkatesh G.

January 3, 2016 - 1:42am
Response to venkuusg

Hi

I have used property-set-html and set the results stream into a html stream and used the same reference in pyData property for pyAttachment page.

Thanks

Venkatesh G

October 12, 2016 - 2:11am
Response to venkuusg

Can u pls tell to us in detail what you did?