-
In the Automation Details panel, under Automations, drag and drop the Google Authorization automation you created in the previous tutorial. This will allow you to authorize SAP Build Process Automation to automate your Google Applications.
-
In the Automation Details panel, under Tools, search for the Try activity.
-
Drag and drop the activity into the workflow just below Google Authorization automation.
-
Select the Try activity.
-
Under the activity parameters, as Errors to catch select GmailError
.
-
Now search for the Search Emails (Gmail) activity and drag and drop it into the workflow, just below the Try.
Add Search Emails (Gmail) activity to search for a specific email in your Gmail account. This activity uses GMAIL API to search for emails based on the search filters as specified in the search query Parameters. You can optionally also specify if the search should include spam and trash folders or not. Output of this activity is a list of Metadata of the emails that match search criteria.
-
Select the activity.
-
Under Input Parameters, next to the query field, choose the pencil to edit the expression.
-
In the expression editor, copy and paste the following code:
"subject:" + Step0.searchSubject + " AND from:" + Step0.searchFrom
-
Choose Save Expression.
-
For the includeSpamTrash
field, select false. This indicates that you do not want to search emails in your Spam and Trash folders.
-
Now search for the Condition control and drag and drop it into the workflow below Search Emails activity.
-
Select the control.
-
Change the Step name to: is mail found?
-
Under Parameters for Condition Expression, choose the three dots and select Edit Formula.
-
In the expression editor, copy and paste the following code:
Step3.messageIdentifiers.length > 0
-
Choose Save Expression.
-
Now search for the Read Email (Gmail) activity and drag and drop it into the workflow just below the condition control.
Add Read Email (Gmail) activity to read the contents of the email. This activity needs Message Id and a location to download media attachments (if any). Using this activity, you can download the attachments of an email into your local file system, or you can upload the attachments to Google Drive. You can use the output of Search activity (previous step) to give messageId
input of this activity. Output of this activity is the content and details of the targeted message.
-
Choose the activity and under Input Parameters, choose the pencil next to the messageId
field.
-
In the expression editor, copy and paste the following code:
Step3.messageIdentifiers[0].messageId
-
Choose Save Expression.
-
For location field, select drive.
-
Finally, for markAsRead
field, select true.
-
Search for the Send Reply activity and drag and drop it into the workflow just below the Read Email activity.
-
Select the activity and under Input Parameters, for the replyParameters
field, select Create Custom Data.
-
Select the pencil next to the threadId
field.
-
In the expression editor, copy and paste the following code:
Step3.messageIdentifiers[0].threadId
-
Choose Save Expression.
-
Select the pencil next to the messageId
field.
-
In the expression editor, copy and paste the following code:
Step3.messageIdentifiers[0].messageId
-
Choose Save Expression.
-
For body field, enter: Thanks for sending the list. I will look into it and select the quotes option.
-
Choose Save.
-
Search for Disconnect activity and drag and drop it into the workflow just below Send reply activity.
You will now log a message in the case no email is found.
-
Search for a Log Message activity and drag and drop it into the workflow just below the Catch.
-
Select the activity and under Input Parameters, for message select 2 error
, for type select error and for label enter Normal workflow has interrupted due to some error(s). Please check., selecting the expression in quotes.
-
Search for Disconnect activity and drag and drop it into the workflow just below Log Message activity.
-
Finally you will put an end to the automation in error. Search for the control Stop automation in error and drag and drop it into the workflow below Disconnect.
-
Select the Stop control and under Parameters select the option Rethrow caught error
.