Use Code in RPA

Hasan Kayan
6 min readJun 27, 2023

The RPA development process is basically done by developing processes by using pre-developed software packages in a no-code structure. In other words, it is based on the process of combining blocks of code suitable for general use in every application infrastructure developed without writing code. UiPath, which is one of the most important tools we use while developing RPA processes, works on the same architecture. The processes that we create from drag-and-drop activities can develop complex processes overall, and often allow us to configure these complex processes very quickly and easily.

But does UiPath contain the activities of every operation that can be done with the software? Of course, this is not possible, instead UiPath has several different approaches to continue the development process if the activities are insufficient, providing us with multiple possibilities where activities are insufficient.

Table-1

As you can see at the Table-1 there are three main approach to use your own code in UiPaht. Lets examine each methode…

1- Invoke Code

Invoke code methode is actually an activity in UiPath Studio that allows us to use our own code inside of it. Invoke code activity allows us to write and execute custom code within our automation workflow. We can basically use C# or VB.NET as programming languages. However, we can also use languages like Python but to use Python we have to follow some extra steps, maybe later we can use that to. For now lets understand Invoke Code.

As I mentioned before, Invoke Code is an activity that we can use in our workflow. When we add this activity, Click Edit Code → Write your code → Add Packages. Now you have your own code inside you workflow. Here I can give you a few tips, do not add namespaces in code, just add packages to your workflow by package manager. The Invoke code activity does not deal with the library usage in the code, the packages that the code depends on are added directly to the project.

2- Own Activity

This is actually a very large topic but for this article I will write a superficial expression, later I will write much more detailed article just about this topic. There are two main methode to create your own activity for UiPath Studio, we can use .NET Class and publish it as Nuget Package but we have to manage all file structures and configuration for UiPath Studio on the other hand we can directly use UiPath Activity Creator extension for Visual Studio.

UiPath Activity Creator uses .NET 4.6.1 in its infrastructure and creates its own structure within the framework and offers us the opportunity to develop activities here. Here again, there is an architecture based on the .NET Class structure. When the first project is created using the extension, it outputs four basic folders, namely Activity, Design, Project and Shared folders.

The project folder contains dependencies, packages and configuration structures, so we usually don’t need to do anything detailed here. The folder where the most work will be done is the Activities folder, this is the area where we will write our code and host the program logic. The Design folder is the folder that will allow us to publish the build structures that we will output the project, the design of the activity interface and the dependencies.

Extension allows us to create activities in a very easy way. By clicking Add Activity, we create the main structure of our activity by defining the name of our activity, input and output variables.

In the window that opens after saying Create activity, we have two options, Create or Import.Import allows us to customize any class or other activity and use it in our own structure, while Create allows us to create an activity from scratch that is completely our own.

After saying Create, we come to the activity addition area where we can easily add and name an activity. When creating an activity, we can choose its type, create a time dependency and add a logo. By clicking Properties, we can add inputs and outputs to our activity and mark these inputs and outputs as Required.

After completing the activity creation process, it remains to write our code and create the program logic. After completing our operations here, we can make our activity ready for use by publishing a Nuget Package. There are some tricks to creating activities, which we will examine in detail in another article in the future.

3- Script Activities

Script activity is a feature in UiPath Studio that allows you to use your own code in UiPath workflows using different scripting languages. Script activity is typically used to run code written in Python, PowerShell, or other scripting languages. There are main steps for Script Activity it is very simular to Invoke Code but its for Script Languages.

→ Drag and Drop: To add a Script activity to your workflow in UiPath Studio, you need to drag and drop this activity to the desired location.

→ Language Selection: After adding the Script activity, you need to select the scripting language you want to use. UiPath supports common scripting languages such as Python and PowerShell.

→ Script Editing: The script editor for the selected scripting language will open and you can write your own code here. You can implement your business logic using syntax and properties specific to the scripting language.

→ Input/Output Variables: Script activity allows you to define input and output variables that allow you to exchange data between the script code and the rest of the workflow. With these variables you can send data and receive results or modified data.

→ Execution: When the workflow comes to the Script activity while running, the script code inside UiPath Studio is executed. It interacts with the workflow using the input and output variables you define.

→ Error Handling: You can manage errors that occur within the Script activity with try-catch blocks. UiPath provides the possibility to catch and handle exceptions that occur within the Script activity, so you can apply appropriate error management strategies.

The Script activity enables you to use complex or specialized functionality in UiPath Studio that cannot be provided by built-in activities. It helps you create a more flexible and extensible automation workflow using custom scripts and languages.

Thank you for your time, if there is anything you want to ask please contact me.

E-Mail: hasankayanformal@gmail.com
E-Mail: hasankayan2000@hotmail.com
My Linkedin: https://www.linkedin.com/in/hasan-kayan-37a59319b/
My Github: https://github.com/hasan-kayan
My Twitter: https://twitter.com/hassannkynn

--

--