An introduction to RPA programming with UiPath Studio
The promise of RPA software is that it can quickly and easily create reusable and repeatable tasks.
Companies such as UIPath, Automation Everywhere and Blue Prism offer “low-code” or “no-code” development environments to make these products as egalitarian as possible so that experienced and young developers of Robotic Process Automation (RPA) can create and automate them can use robots.
First, install the IDE and build a basic UiPath Hello World application to get familiar with the tool.
How to Learn RPA Programming
- Variable initialization techniques;
- Conditional logic with if-then-else statements;
- Iterative logic using for, each, and while loops;
- Interactive input and output routines; and
- The use of try-catch blocks to implement UiPath error handling.
RPA project creation
Use a number puzzle game to learn RPA programming.
Variable initialization in UiPath Studio
The application requires three variables, which means the Multiple assignment Activity must be drawn from the activities Tab on the main workflow window. Use this activity to create the following variables:
- A variable called number of type int32 – initializes it to the number 0;
- A variable called secret key of type int32 – initialize it to 5; and
- A variable called suspect of type int32.
UiPath Studio provides an activity to initialize multiple variables at once.
UiPath Studio do-while loops
In order to iteratively prompt the user to guess the PIN, a programmer must put a do-while loop under the Multiple assignment Activity. The loop continues as long as the secret number is not equal to the user’s guess, which means the following logic is entered for the condition of the loop:
rate secret numberN
Insert in the do-while loop. added Input dialog Activity to prompt the user for a number and store the answer in the variable suspect.
Assign the following values for the input dialog:
- Put the label on “Choose a number between 1 and 10“.
- Put the title on “What will you choose“.
- Put on the result suspect.
Conditional statements from UiPath Studio
Because the user’s guess is stored in a variable, the application requires conditional statements that direct the user to guess higher or lower as necessary. Start the conditional logic by adding If Activity on the sequence.
This first If Statement simply checks that the user guessed the correct number. Add the code to the condition of the If Activity as follows:
rate secret numberN
By doing Then Clause, add a nested If Condition and indicate whether you want the user to guess higher or lower. For the state of the nested If, check if the guess is less than the secret. Add a Message box to both Then and Otherwise Conditions that direct the user to guess higher or lower.
RPA programmers typically use nested if-clauses in their code.
Complete the RPA programming app
The final operation added to our application is to: a Message box Activity after Do while Activity that tells the user how often it took them to guess correctly. The content of the Message box would be as follows:
“Right! You had to guess” + count.ToString + “.”
When all of this is done, a programmer can run the RPA program. The number puzzle game will play, and if the user guesses the number five, the program will trigger a window telling the user that they guessed the secret number correctly.
This is what the completed RPA programming project looks like when it is completed.
UiPath exception handling
This application has a minor bug. If a user of the published UiPath app provides non-numeric input, it throws an exception. There are many ways to do input validation, but a simple solution for this example is to put the entire do-while loop in a try-catch block. A programmer can accomplish this by using the UiPath. adds Try catching it Activity on the side. Move the loop into the body of the experiment and then catch the System.exception.
If you want to improve your RPA programming skills, build on this UiPath Studio tutorial by creating a few projects of your own. I always recommend developers use the concepts taught here and see if they can write rock, paper, and scissors application. Completing such a project on your own will help strengthen the basics of software development and take you one step further on your path to mastering and learning RPA programming skills.
The source code for this UiPath Studio tutorial can be found on GitHub.
View all videos