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: 

Introduction


Many business processes start with a document (e.g. a purchase order or a supplier invoice). Such documents don’t always come in a structured and fixed format. Therefore, their handling often involves people that read the documents, check and extract the data, and input the data in a system for further processing. SAP Intelligent Robotic Process Automation can automate many of the steps of such processes or tasks. To further increase the degree of automation, SAP Intelligent RPA can be integrated with specialized software that is focused on recognizing and extracting necessary entities from semi-structured or unstructured documents. In this post, we show how to use SAP Intelligent RPA in combination with ABBYY FlexiCapture for an end-to-end automation of an example use case.

Example Business Use-Case


Scenario


“An employee of a company regularly checks his inbox for emails that contain supplier invoices as scanned attachments. If such an email is present, the employee verifies and extracts the data manually and uses it to create a supplier invoice in the company’s S/4 HANA system. Due to the high number of such emails regularly coming in, the employee has to perform this repetitive task many times per day.” 

Analysis


A first look at the scenario yields the following three subtasks that the employee needs to perform:

  1. Reading the email inbox and finding emails that need to be processed

  2. Verifying and extracting the data out of the scanned documents attached to the emails

  3. Creating a supplier invoice in S/4 HANA


The first and last parts can be automated using SAP Intelligent RPA, while the second part can be automated using document-processing software, such as ABBYY FlexiCapture. Thus, a first SAP Intelligent RPA bot can scan the inbox for unread emails containing certain keywords and extract the attachments from these emails and hand them over to ABBYY FlexiCapture. FlexiCapture would then extract the necessary key-value pairs from the document and use the data to trigger a second SAP Intelligent RPA bot. This bot would use the data to perform an UI Automation that creates a supplier invoice in S/4 HANA. This raises the question on how to integrate the two solutions, so that the process runs end-to-end. For this, we can use the following interfaces:

  1. For the integration of subtasks A & B, we use the ABBYY Hot Folder. Thus, the first SAP Intelligent RPA bot will extract the attached document(s) and copy them to the Hot Folder. ABBYY FlexiCapture can be configured to periodically scan the Hot Folder and process any new documents that it contains.

  2. For the integration of subtasks B & C, we use an API Trigger (more information on this can be found in this blog post). With the help of a custom export script, ABBYY FlexiCapture can run an API Trigger and provide the extracted data as input to the second SAP Intelligent RPA Bot.


The following diagram shows the general workflow:


One important side note is on the performance of the data extraction algorithm. In real-world scenarios, it could be that some documents are more difficult to process (e.g. due to the quality of the scanned document) and the algorithm cannot fully extract the necessary data with a high confidence. In such cases, human experts that know the particular domain of the use case can take over and verify the results manually. This can additionally help improve the extraction. As this is not the main topic of this post, we will not dive into details, but we do however note that ABBYY FlexiCapture provides features that enable manual verification.

In the next part of this post, we explain the configurations required to implement the above workflow with SAP Intelligent RPA and ABBYY FlexiCapture.

Configuration


The next paragraphs describe the prerequisites and then each integration part in detail.

Prerequisites


To be able to combine the two solutions, the following conditions have to be met:

  1. The Desktop Agent that executes the first SAP Intelligent RPA bot needs to run on a machine that has access to the Hot Folder

  2. ABBYY FlexiCapture needs to be able to execute web calls to the SAP Intelligent RPA tenant, in order to run the API Trigger that starts the second SAP Intelligent RPA bot.


Copy attachment from email to local/network folder


Using the SAP Intelligent RPA “Microsoft Outlook” extension, we can use the method ctx.outlook.mail.attachmentSave() to save attachments to a specified directory, e.g.:
ctx.outlook.mail.attachmentSave(i, "C:\\HotFolder\\" + ctx.outlook.mail.getAttachmentsName(i)[0]);

The parameter “i” corresponds to the index of the attachment in the current collection of selected emails. The second parameter sets the path used to save the attachment. Here we additionally use the method ctx.outlook.mail.getAttachmentsName() to set the name of the attached file.

Configure ABBYY FlexiCapture to scan Hot Folder


To activate the Hot Folder in ABBYY FlexiCapture, go to Administration & Monitoring, then to the Projects tab of the FlexiCapture server and turn on the corresponding toggle:


To specify the relative path and other settings of the Hot Folder, open the Project Setup Station and navigate to Project -> Image Import Profiles and add or edit the current profile:


To activate the scanning of the Hot Folder and configure how often this is done, choose the “Image Loading” Tab:



Configure ABBYY FlexiCapture to run API Trigger using extracted data


To start the second SAP Intelligent RPA via the API Trigger, one option is to use a custom export script within the Document Definition. For this, in the Project Setup Station, first navigate to Project -> Document Definitions… and edit the document definition in question. This opens the document-definition window. Here, navigate to Document Definition -> Export Settings… This opens a pop up where the custom export script can be added:


Custom-scripts enable executing code (in e.g., C#, VB or Javascript) that is triggered every time a certain event happens during the processing of an event (e.g. when exporting results to a file). For certain events, such as the “after export” event, the script has access to the fields extracted from the document. In the following we show an example custom-script that is executed during the export of the results to a file. The script does the following:

  1. Obtains a JWT token using the SAP Intelligent RPA service key (more information on how to obtain a service key here)

  2. It loops through the processed documents and

    1. extracts the necessary values that are subsequently assembled into a JSON input for the API Trigger

    2. Builds the necessary JSON input for the bot and calls the API Trigger to run the bot




using System.Net.Http;
using System.Net.Http.Headers;
using System.Net;
using System;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json;
using System.Linq;
using Microsoft.VisualBasic.FileIO;

// Configuration
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

// API Trigger endpoint and irpa-trigger-token
string APITriggerURL = "";
string irpaTriggerToken = "";

// OAuth credentials for calling API Trigger
string oAuthClientId = "";
string oAuthClientSecret = "";
string oAuthURL = "";

// obtain JWT Token using OAuth Credentials
HttpClient client = new HttpClient();
var basicAuth = Encoding.ASCII.GetBytes(oAuthClientId + ":" + oAuthClientSecret);
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(basicAuth));
var response1 = client.PostAsync(oAuthURL, null).Result;
Dictionary<string, string> oAuthBody = JsonConvert.DeserializeObject<Dictionary<string, string>>(response1.Content.ReadAsStringAsync().Result);
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", oAuthBody["access_token"]);

// Loop over documents, create the corresponding input and execute API Trigger
foreach (IField order in Document.Field("Invoice Layout\\PurchaseOrder").Items)
{
// Build the json input for the API Trigger
Dictionary<string, object> body = new Dictionary<string, object>{
{"irpaTriggerToken", irpaTriggerToken},
{"invocationContext", new Dictionary<string, object>() {
// define invocationContext here
}
},
{"input", new Dictionary<string, object>() {
// here is an example of building an input json using the fields extracted from the document
{"InvoiceData", new Dictionary<string, object>() {
{"CompanyCode", Document.Field("Invoice Layout\\Vendor\\VendorId").Value},
{"Number", order.Children[0].Text},
{"EmittedDate", Document.Field("Invoice Layout\\InvoiceDate").Value},
{"PurchaseOrderNo", order.Children[0].Text},
{"Currency", Document.Field("Invoice Layout\\Currency").Value},
{"TotalGross", Document.Field("Invoice Layout\\Total").Value},
{"VendorName", Document.Field("Invoice Layout\\Vendor\\Name").Value}
}
}
}
}
};
StringContent content = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json");

// API Call to trigger IRPA bot using the json created above
client.PostAsync(APITriggerURL, content);
}

For the script to run, the missing values of the variables need to be filled. Additionally, the libraries imported at the beginning of the script need to be enabled in ABBYY FlexiCapture. For this, go to Project -> Project Properties… -> .Net References and add them via “Standard assembly name” or via “Attached file” depending on the nature of the library.

Conclusion


The goal of the post is to illustrate the ease of combining SAP Intelligent RPA and ABBYY FlexiCapture in an end-to-end fashion. The combination consists in a series of steps and the development of a simple custom export script. Based on the template above, use cases involving other types of business documents (e.g. purchase orders, etc.) can also be implemented. This way, we can automate mundane and repetitive processes, and humans can concentrate on higher-level creative tasks.

To make it easier to reuse the above configuration, we have included the custom script and the bot in a package available in our bot store. More information on the bot store can be found here. Additionally, join us for a webinar explaining the combination in more detail.

If you have questions or comments, do not hesitate to post them on our question page or on the topic page.

Learn More

For more information on SAP Intelligent RPA,
2 Comments