SAP Intelligent RPA 2.0 : Understand the Outlook library to read mails
Hello bot builders !
With SAP Intelligent RPA (and especially SAP Intelligent RPA 2.0), it is quite easy to build bots to automate your processes. But when it comes to Outlook, things might become a little complicated if you don’t have a quite good understanding of how this library is designed and how it works.
Overview of the library
Let’s do a quick exercise. Imagine you’re at home and you need to do some homework. You enter the library and here is what you see :
First thing to do : pick the books you need.
Then you sit at your desk, with a stack of books in front of you:
What’s next ? You cannot read all of them at the same time so you need to pick one book from the stack to start your work.
Now, replace the word book with mail. Here is what we get :
- Select the mails you need
- You’ve got a stack of mails
- Pick one mail to work with it
You get the idea. Outlook library works the same way : you will search for emails, and then you will work with what we call the Context Current Email (also known as CCE). Don’t forget this name, as it will be used later in this blog post.
Again, you cannot have multiple Context Current Emails, just like you cannot read multiple books at the same time : you read one book (even partially) then you pick another book and start reading.
First thing to do when you want to work with Outlook in an automation : add a dependency to Oulook library !
Open the settings of your project, and simply add the Outlook library (see below) :
Ok so now we can start working with Outlook. Using the library analogy, to be able to read some books, we must enter the library: that’s why we always use the activity Open Outlook instance before using any other Outlook activity.
And when we are done, we leave the library : we use the Release Outlook instance activity. So we get the below structure :
Ok and now ?
How to select the CCE ?
To select the mails, we use the Search Email activity : it’s the first activity in the category [irpa_outlook] Email so you cannot forget to use it !
Moreover, this activity is quite easy to use ! When you edit its properties, you have a popup where all you need to do is select what you need to search (and also in which folder, etc.) :
Note : searchCriteriasList is… a list ! So you can add as many criteria as you wish.
This Search Mail activity kind of returns a list of mail matching the criteria. It represents the stack of books.
Warning : the Search Mail activity does not exactly return a list that you can save in some variable. The result is stored internally and all the activities will work with this “hidden” result.
Wait… We have a list but we can only work with one item at a time ?
Yes ! And here is how we can do it.
Work with one email at a time
To work with these mails, we need to insert a loop in our automation. For each iteration, we make sure that the CCE exists (at the beginning of the loop) and we move to the next item in the list (at the end of the loop).
A picture is worth a thousand words :
Let’s detail this piece of automation :
- We enter the library
- We search for some mails, depending the criteria we set
- Using this loop we will be able to work with all the found mails
- We need to make sure the CCE exists, using the Is Context Current Email Not Exist activity
- We test the result of the previous instruction. If true, let’s get out from the loop
- Otherwise we go to the default branch
- Here we can do whatever we want with the CCE (get the subject, get the recipients, get the attachments, etc.)
- Once we’re done with this CCE, let’s take the next item in the list and loop
- We leave the library
|In Step 7, do NOT use the Delete Email activities, because they change the Context collection. If you want to delete multiple emails, please have a look at the documentation.|
|There are similar activities which are available to check that the CCE exists. Make sure you’re using Is Context Current Email Not Exist in that case.|
Note : all the activities you can use when the CCE exists are available under the categories emailItem and properties
And now ?
Now it’s up to you to build automations where you can work with tons of mails. For example you can get all the POs you received, and for each one of them, download the attached files and process the PO in S4 !
As you could see, there was no need to write a single line of code, and that’s why working with Outlook has never been so easy !
Note : you can also have a look here to learn the best practices about Oulook on our Help portal.
Find more information on SAP Intelligent RPA: