SAP Automation with UiPath


Hello. Welcome to the optional training, SAP Automation. In today’s video you’ll learn about automating
this widely popular platform for enterprise-resource-planning. Generally, SAP has been quite tedious to automate,
but by the end of this video you will see that UiPath makes the whole process rather painless, whether your SAP configuration has scripting enabled or not. Most techniques
you will use are fairly standard – things like automatic recording, manually inserting
clickText actions, sending keyboard shortcuts, and extracting text and a couple of SAP specific approaches too. Because it does have
its own peculiarities, and while you could work your way through them on your own, we’ll
give you a few tips & tricks so you can hit the ground running. As a testing platform we’ll use 2 human-resources
forms – or transactions as they’re called in SAP: one displaying employee history…
and the other for adding new employees. But before you start automating,
you should enable SAP scripting, both on the local machine where the robot will
run, and on the server. It’s a setting that needs to be performed
only once to give UiPath direct access to SAPs interface. To enable it on the local machine, on the Toolbar, go to the
last button, Customise Local Layout, and Options. Then go to Accessibility&Scripting, and Scripting. Here, you will need to enable scripting and
disable the other two. And hit ok. For the server, log on to the Sap server and
go to transaction RZ11. Here, for the parameter name type “sapgui”
slash “user underscore scripting”, and enter. In this window press the ChangeValue button
on the toolbar, and set the new value to True; and click save. That’s all. If for whatever reason, enabling these options
is not available to you, then UiPath will not be able to uniquely identify some UI elements, so you’ll need to apply other methods that are still 100% reliable. Right; now that’s taken care of, we can Make sure you watch the video detailing specific
image-based techniques, if this is your situation. When you first open SAP you are greeted with
the logon window; we also have the recorder open. So normally you’d go to Connections, and
double-click the server you wish to connect to. Especially without scripting enabled. The two panels are seen as blocks,
even though the toolbar buttons and other So normally you’d go to Connections, and
double-click the server you wish to connect Fortunately the solution is quite simple. When trying to record these steps, we encounter the first SAP quirk and the one that you’ll encounter most often. Especially without scripting enabled. The two panels are seen as blocks,
even though the toolbar buttons and other elements are identified individually. Fortunately the solution is quite simple. We’ll use a clickText action. Exit the automatic recording mode and manually add a clickText action, by going to Text, mouse, click; and then indicate the desired
element. UiPath will show the Screen Scraping Wizard. If this is your first encounter with it, here’s
how it works: this is the preview area showing you the text elements identified inside the
selection you just made. The next step is to copy from here the exact
text corresponding to what you want to click on, and paste it here, in the Text-to-be-Found
field. That’s it; now when you click continue, UiPath
will perform the click: in our case on the Connections folder, showing the list of servers. Here, you can use another clickText to start
the Sap session: again, in the recorder go to Text, then Mouse, but this time, to Double Click to start the connection. And click the desired region. This shows up a bit more information than the left pane because this selection included the headers of the text box too. the headers of the textbox too. No matter, just fill-in the text you want
to click on, and you are done. But don’t click Continue yet, let’s see
what other options we have for this clickText wizard. This one is purely informative, it just tells
you the current scraping method; Native is automatically chosen because it’s 100% accurate, unlike the OCR method, which can have slight imprecisions. And these 2 buttons let you pick another elements or regions to scrape. Below the preview, Occurence is the situation when multiple instances of the same text are present in the selection. It allows you to choose which instance is
the correct one. Set Mouse Position is useful when you want
to click somewhere relative to a text element. You’ll see a bit later on a different example
how that works exactly. And TestClick performs an actual click so
you can check if and how the clickText works. When you click Continue, UiPath will perform the Double Click and the logon window pops up. This is a pretty standard window so you can record interactions with no issues. We’ll fill in the username, password, and
add an Enter at the end to proceed. If you’d like to use operating system credentials for secure login you should have a look at the Window’s credentials article on our website. Let’s stop the recording and see the generated
activities. We have the clickText that selects Connections,
the one that doubleClicks the server, and the typing of the user & password. So far so good. Let’s start a new recording to see what
other automation quirks we can identify. In the beginning I said we’ll use two SAP
personnel-management modules. They are available here, deep in the menu,
but we’ll use a shortcut to access them: simply type the code of the transaction that
we want to bring-up, in the command-field up here. The one we’ll use now is called PA10, but
all modules have special codes, so it’s a quick and reliable method of opening them. This module is for viewing employee information
starting from a valid employee ID. You can type the ID and some basic information
will show up. The interesting element is this little button
that appears only when this field has focus. It is used extensively throughout SAPs interface,
and it can be a bit “slippery”. It opens a window that helps you fill in the
current field with data. In this example find an employer ID by adding and combining filters from the left pane. Let’s say you need to find in Sap a user
based on nationality and marital status. It’s not necessarily the most useful example,
but you’ll learn how this type of buttons and controls can be automated. So, for each added
filter you can type a value here… or, if you don’t know it, click the little button
associated with it. And double click any of the options to use
its value. These are the same types of buttons as the
ones that opened this window, but for different data. And then click finish to bring up the result list,
showing all the employees matching the set filters, and finally, double click any one
of them to use its value. And enter to display it. This screen shows some basic information about
the user, but for a detailed view, you need to press the Display button. Notice how the tooltip shows its keyboard
shortcut too. It’s very useful because this means we can
reliably use keyboard commands to do various actions. Especially since most important buttons have
associated shortcuts. Here you can see a more detailed history for
an employee, but it’s read-only and you can only extract information. All these elements are easily accessible through
the recorder though, so no problem here. Good.. Next, let’s see how to automate all these
steps, because there are a few tricky parts. After the login, this is the main screen that
you are presented with. The automatic recorder works on most toolbar
buttons and elements, but not on this menu tree – it’s all one block. We were planning to use a shortcut anyway,
so just type the transaction code PA10 here, and add an enter key. On this next screen we have a couple of options
for the employee ID field. The simplest is to click here, type the ID,
and add an enter key. Nothing more to it. The other option is to press its little button. But the recorder cannot directly press it,
and on top of that, it automatically hides when this field is not selected. But here’s a very easy workaround. Hit escape to pause the recording and add
the first click action to activate the button. It shows up briefly but disappears when the
window loses focus. That’s ok; add a second click action, and
notice that the window and textfield are now active, and the button is clickable. And here’s the popup. If before you got a chance to click the button,
the textfield somehow lost focus and the button is not showing up… you can hit the F2 key
to temporarily pause the recording… click to focus it… and when the countdown finishes,
recording resumes and you can finally click the button. That’s all; let’s see if it worked. Here’s the Type that starts the transaction
PA10, the click that activates the button, and the actual pressing of the button. First let’s test it. Looks like it’s working, let’s take a closer
look to see how. As you can see, the only difference between
the two clicks are the offset coordinates. The offset is calculated relative to the indicated
element – or from its top left corner, to be exact. Resulting in a click that lands exactly on
the button, every time. For practice, let’s delete these 2 generated
click actions and recreate them manually. So add a new click… indicate the text field…
and duplicate the activity. The default click position is in the center. We’ll change that to the bottom-right corner
instead – because it’s closer to the tiny button – and add an offset of a few pixels. Negative 5 pixels on both axes should be ok. In case you’re not familiar with screen coordinates
systems, positive axes are to the right and down. So that’s how you interact with ephemeral
UI elements – by simulating human actions that activate the desired element. Further on, let’s see how to expand these
folders, and click the associated checkboxes. Automatic recording won’t work, because individual elements are not accessible, so we have to
fallback to the clickText method used earlier, but with an offset. Start by going to text mouse click and indicate
the area. In the lower
box we’ll copy the text we want to click next to, “personal data”. And to offset the click, use set mouse position. Manually indicate the position… on the little
expand arrow. That’s it; hit continue and the click will
be performed. Then repeat the process for the other two
checkboxes: add a click text… copy the name of the element… and set mouse position,
this time indicating the checkbox. On the right-hand side most of the elements
are accessible through automatic recording, but these specific text fields don’t trigger
an input field. No problem: we’ll just manually add a type action
for each field. And a few more: a click to accept the
changes… a doubleClick to choose an employee… and another click on the View button. In this screen, all the fields are readily
accessible, so we can get any piece of data we need, no issues here. But there are some controls that can be a
bit tricky to extract: tables and checkboxes. All Individual table cells can be read, but
what happens when you want to extract a whole column or the full table? To see that, we’ll first start from a single
cell. Let’s save&exit for now, and take a look
at what we recorded. The first action clicks to the left of the
“personal data” text found on the screen, on the expand arrow. The negative offset on the X axis is a good
indication of where it performs the click. The other two are similar, but with a positive
X offset, which means they will click to the right of the indicated text, on the checkboxes. The next ones are simple Type actions, clicks,
and a couple of GetValues; pretty standard. The last one though, it extracts a table cell
value, and we’ll use it to extract a whole column – or row – from the table. For easier testing, we’ll cut it from here…
and paste it in a new… sequence. Perfect. If we take a look at the selector for this
getValue activity, we notice the row and column are explicitly written. That’s quite handy because it means we can
use a while loop to cycle through all the rows in the table. So, add a doWhile… set up a counter for it…
and move the getValue inside the loop. Now open its selector, locate the tableRow
argument, and delete it. In its place, simply put the counter variable. Oh, and remember the numbering of rows and columns starts from 0, so the first row is row 0. Ok. Now add a writeLine to print it all out, and run. And here they are. Of course, you can apply the same method for
multiple columns, or for rows, or for whole tables that you can extract and use further
however you want. A special case for this extraction technique
is when you don’t know the number of rows in the table. What then? Well, the solution is a bit counterintuitive
but also quite simple. It’s based on the fact that in SAP you cannot
read outside of a table, it’s nothing there. So if UiPath tries to read after the last row,
it will throw an error. And here’s how to exploit that in UiPath: modify
the doWhile to make it loop forever; then add a tryCatch activity…
and move the entire doWhile loop inside the try block. Technically, that’s all. Now, when the counter goes beyond the last
table row, it will encounter an error that will be caught by the Catch block, so it won’t
actually fail. We’ll also give the GetValue activity a
shorter timeout, because its failure is what will trigger the catch. Then add an all encompassing system exception,
and just for illustration purposes, throw in a WriteLine activity. And when we run… we see the results followed
by the Catch message, which means everything went smoothly. And the other element that requires a bit of special treatment, the checkbox. You can click it on & off using regular
recording, but to get its state, you have to read its attributes. It’s fairly easy: use the aptly named GetAttribute
activity… and indicate the checkbox. UiPath will read and expose all its properties,
but the one you are interested in is this one, Check. Then create an output variable – we’ll call it Check – and show it in a msgBox. And here it is. Okay, as you’ve seen, output methods are pretty
easy: all elements are accessible in the usual manner, you only need to setup
some loops for tables, and get attributes for checkboxes. And this brings us to the end of today’s training. I think that by now you’ll agree that SAP is generally straightforward to automate, with a few quirks here and there that have simple workarounds. The main takeaways of this video should be
these: when automating SAP, start with recording
the actions; most of the time it will work fine. To interact with unrecognised elements you
can use clickText & clickImage; and keyboard shortcuts to reach difficult buttons or menu
items. When dealing with an elusive UI element – like
the tiny button to the right of some text fields – simply find a way to recreate the
actions a human would do to activate that element. For tabular data you have to use loops, although
that is hardly SAP specific. The interesting part is the special case of
reading a table of unknown size. The technique you saw was to read each row,
in an infinite loop, until the operation fails. All that in a try-catch block to prevent an
actual failure. And for reading special elements, use the
getAttributes activity – it shows a bunch of hidden information that can prove very
useful. That’s about it. Till next time, bye!

9 thoughts on “SAP Automation with UiPath

  1. 00:00 – Introduction
    01:02 – Enable Gui Scripting
    02:14 – Sap Automation – Login
    05:20 – Sap Automation – PA10
    08:00 – Buttom show whit focus
    12:20 – Tables
    16:08 – Check – Box
    17:50 – Resume

  2. How do we automate SAP Business Client? Because of some security policies, we cannot use SAP Logon and we are asked to use SAP Business Client instead (NWBC.exe). But UiPath doesn't recognize the elements.

  3. Amazing tutorial. Really gave some good insights into basic SAP automation. I wonder if there is a chance to get a video of similar quality about creating records (in whatever business context) in SAP, eg. creating a personal record or a sales order or something similar?

Leave a Reply

Your email address will not be published. Required fields are marked *