Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
Chaitanya_Priya
Product and Topic Expert
Product and Topic Expert
Introduction

This blog post explains the features which are used day in and day out when a BOT is developed and is a submission for the SAP Intelligent RPA Tutorial Challenge


1.Creating a Dynamic Email Content

Generating an automated email in one of the most common steps in executing any bot.

The content in the email needs to be changed according to the user. For example, for every mail the Email salutation the name changes. The name can be made Dynamic.

We generally write the HTML email body in the code and send the mail. There are scenarios where the Email content is too big. The better approach is to have the HTML email content in a text file and add special characters in the place where the content has to be changed Dynamically.

2.Printing data in PDF

There are business scenarios where we need to print the data in PDF. We don’t have the PDF activities in SDK. The solution is to print the data in MS word and save it as a PDF.

3.Looping 

Since bot executes repetitive tasks, it would be a good approach if we use the Looping activities provided by SAP IRPA.

Workflow Sequence:


1. This bot reads the email content from the text files replaces the dynamic content.


2. Sends an email with the Dynamic Email Content.


3. Searches the unread mails.


4.Loops through the unread emails and prints the email content of all the mails in a word document.


5.Converts word document to a PDF.


 

Prerequisites :

Create a Folder in C drive C:\Users\Public\IRPA_projects\DynamicEmail\Data.(The path can be changed)

Create a text file Mailbody.txt.Copy all the HTML email content to a text file. Replace the dynamic content with Special characters as shown below.



Create a word document with the name Feedback.docx.This document will hold all the unread email content during the bot execution.


Include Word, Outlook libraries in your project.


Right-click on the Include script Library as shown below




Sequence of Steps

1. Create a project and the workflow with the sequence of the same steps.

Get Dynamic Email Body, Send Mail, Retrieve Unread Email, Set Email Index, Insert Word Content are Custom activities.



Create a context with the folder structure and items.



Set the properties for the Open Word activity. Enter the file name.



Set the exit condition for Exit Loop activity.

Enter the name of the PDF Document for the Save as Word Activity.


2. Step: Get Dynamic Email Body(reads the email content from the text files replaces the dynamic content.)



rootData.myData.sMailBody = mailBody.replace('####', 'Chaitanya Priya');
rootData.myData.sMailBody = rootData.myData.sMailBody.replace('$$$$', '4');

 

3. Send mail Step(Sends mail)
ctx.outlook.mail.create({ To: 'chaitanya.priya.puvvada@sap.com', Subject: 'DynamicEmailContent' }); 
ctx.outlook.mail.setBodyHtml(0, rootData.myData.sMailBody);
ctx.outlook.mail.send(0);



4. Retrieve Unread Email Step(Retrieves the unread email from Outlook.I have set the maximum unread emails to 3)
 ctx.outlook.mail.search({
filter : "\"" + "urn:schemas:httpmail:read" + "\"" + "= 0",
maxRow : 3
});



5.Step to Set Mail Index to the length of the array of Unread emails .



 

6.Exit Loop Step (Exists the loop when the counter reaches the length of Unreadmails Array



 

7. Insert Word Content Step(Inserts the email content from the Unread email array and prints in the word document.
ctx.outlook.mail.retrieveMail({EntryID : rootData.myData.aUnreadMails[i]['EntryID'], StoreID : rootData.myData.aUnreadMails[i]['StoreID']});	rootData.myData.sWordContent = ctx.outlook.mail.getBody(i);
ctx.log("From: " + rootData.myData.aUnreadMails[i]['Sender']);
ctx.log("Subject: " + ctx.outlook.mail.getSubject(i));
ctx.log("Body: " + ctx.outlook.mail.getBody(i));
ctx.log("Body from root data: " + rootData.myData.sWordContent); var result = ctx.word.document.insertText(rootData.myData.sWordContent );
var result2 = ctx.word.document.insertParagraph( );

 



8. Save as Word Step(To save  the Word as PDF value 17 needed to be added in the code)



 

Conclusion

Now you should be able to utilize the MS word functions, Outlook functions, looping functions and create the dynamic email content.

Execution of BOT.



Folder structure after the bot execution is completed.

12 Comments