Invoice registration in SAP workflow
Script overview
On the high level the script consists of the following actions.
- Open an image PDF invoice, recognize required information using OCR, and put it into string variables.
- Open and log in to the SAP GUI desktop client.
- Find the MIRO transaction and enter the company code.
- Enter the previously recognized data to the required fields.
- Post the first invoice.
- Open a searchable PDF invoice with Mozilla Firefox and extract data using XPaths.
- Enter the data in the required fields.
- Post the second invoice into the system.
Let's explore these steps in detail.
Environment
- Windows OS that meets System Requirements
- SAP GUI v. 7.40-7.50 connected to some environment
- SAP GUI should be configured as described here
- Screen resolution should be one of these:
- 1920 x 1080
- 1600 x 900
- 1366 x 768
- 1280 x 1024
- 1024 x 768
- Mozilla Firefox
- Adobe Acrobat Reader (recommended version 19.012)
Script variables
| Variable name | Type | Description | Default value |
|---|---|---|---|
folder_path | String | path to the folder with input files / invoices (needs to be set up before running the script) | |
ok_code | String | transaction code | MIRO |
company_code | String | company code | |
amount_with_tax | String | amount of money in the invoice including tax | |
currency | String | invoice currency | |
amount | String | amount of money in the invoice without tax | |
tax | String | amount of tax in the invoice | |
tax_code | String | tax code in your SAP GUI | U1 |
purchase_order | String | invoice purchase order | |
login | Secret | SAP username (needs to be set up before running the script) | |
password | Secret | SAP password (needs to be set up before running the script) | |
quantity | String | quantity of items in the invoice | |
invoice_date | String | current date converted to string | |
transaction_type | String | required to choose the right transaction type | Invoice |
sap_path | String | path to saplogon.exe (needs to be set up before running the script) | C:\Program Files (x86)\SAP\FrontEnd\SAPgui\saplogon.exe |
Script workflow
Open invoice and OCR it
Description: The group opens the invoice, recognizes the text with OCR, and puts it to specific variables.
- The bot opens the first invoice (Launch Application) and switches to it with the Window action, so it appears on the screen.

- The bot extracts the needed data using OCR. Exception handlings are added so the bot can extract data on different screen resolutions.

Log in to SAP GUI (reusable)
Description: The group opens SAP GUI and logs in to it.
To reuse the group, make sure you have added the required SAP GUI credentials in Secrets Vault in WorkFusion Studio. If you add another secret entry, change the following variables:
login– SAP GUI username (Secrets Vault > Key)password– SAP GUI password (Secrets Vault > Value)
note
All Mouse clicks in SAP GUI are automated using the Inspector tool.
The bot launches SAP GUI using Launch Application, clicks on the Log on** button (Click Mouse) in a specific window, and pastes the credentials into the required fields (Enter Keystrokes).

Create and post incoming invoice
Description: The group allows to open the MIRO transaction for a specific company, fill in all the required invoice fields extracted previously with OCR, and post into the system.
- Create and post incoming invoice (reusable). The bot opens the MIRO transaction for a company from the first invoice which code was extracted with the help of OCR. The Window, Click Mouse, and Enter Keystrokes actions are used.

- The bot fills in all the required invoice fields (Invoice date, Amount, Purchase Order, Tax), clicks on the Simulate button, and waits for the Simulate window to open. The Window, Click Mouse, Enter Keystrokes, and Wait actions are used.

- The bot posts the invoice into the SAP system. The Window and Click Mouse actions are used.

Open the second invoice with Mozilla and extract XPaths
Description: The group opens the second invoice in Mozilla Firefox and extracts information to specific variables using XPaths.
- The bot replaces "\" with "/" (Replace Text) so that the file can be opened with Mozilla Firefox.

- The bot opens the second invoice via the Open website action and extracts the needed data using XPaths via the Web Element action, and saves it to specific variables.

Create and post the second invoice
Description: The group creates and posts the second invoice using the previously extracted data.
The bot fills in all required fields for the second invoice and posts it. The Enter Keystrokes, Click Mouse, and Wait actions are used.
