Tips to make better workflows using UiPath.

Photo by Nick Morrison on Unsplash

PA is taking the world by storm. It allows the companies to automate mundane tasks so that their resources could focus on something more important. This is beneficial not only for the company but also allows the employee to get their hands dirty in other areas of the industry as well.

Tools such as UiPath not only allow us to create workflows that can range from simple to pretty complicated(depending upon business logic) but also allows us to do it very elegantly with a drag and drop mechanism.

But dragging and dropping technique can lead to complex looking workflows for simple logical statements.

Here are some of the tips that could help you to make your workflows more efficient-

#1: Using Global Variables.

If you have any experience in programming then you know the importance of global variables. While creating workflows we usually pass all the required variables as arguments to different workflows. The flaw with this approach is that if there is a small change in arguments of any one of the workflow then all other the workflows where it was called has to be modified.

In order to introduce global variables functionality in our workflow, we can use Getter Setter activity.

Getter Setter Activity.

In the above demonstration notice that Import Argument = 0. This means the value in the invoked workflow is being picked from our global variable.

#2: Multiple Assign activity.

When dealing with initialization or assignment of multiple variables we usually tend to a simple Assign activity. This leads to a cluster of activities that can be a bit overwhelming to look at.

For such cases use Multiple Assign activity. It allows us to assign values to multiple variables in one go.

Assign Activity vs Multiple Assign Activity

#3: Finding common and uncommon values between the two lists.

Many times we are facing a situation where we need to extract common or uncommon values among 2 lists. For that, the usual approach is using a for loop with an if-condition activity to determine common and uncommon values.

For finding common values we can use Intersect() method.

Intersect() method Syntax

For finding uncommon values we can use Except() method.

Except() method Syntax
Extracting Commons and Uncommons via ForEach vs Intersect(),Except()

#4: Getting a list of files in a directory.

Often times while performing actions such as reading or writing on a file it is a good practice to check whether a file is already present in the directory or not and making the decision accordingly.

For finding a single file we can use File.Exists() method.

File.Exists() Syntax

Above returns a boolean which can be checked for the presence of the file.

For just getting the list of files we can use Directory.GetFiles() method.

File.Exists() Syntax

#5: Checking if some string is Empty or Null.

Usually, for this task, we go with the equality operator which needs to be used twice for both empty(“ ”) and Null. This approach is fine but String class provides us with a solid way of checking whether a string is empty or null in one go.

For checking empty or null string we can use String.IsNullOrEmpty() method.

String.IsNullOrEmpty() Syntax.

This method returns a boolean which can be used for checking purposes.

#6: Merging multiple collections into one.

List<T> or any other collection type provides a method of add() to add value to an existing list. But if we want to add the content of another list then we need to do it one by one via add().

To merge multiple collections (eg a list) into a single one we can use Concat() method.

Concat() method Syntax

We have to add ToList() at the end as the resulting output of Concat() is of type IEnumerable() which is not as same as List(). So, the ToList() method converts it to the list.

#7: Sending keystrokes multiple times using a single activity.

When we need to send a hotkey in our application, we usually use Send Hotkey activity. The problem is when we need to send multiple hotkeys the number of activities also increase leading to the complex looking workflow.

Not only this, the keys usually have some delays in between as they are being sent via different activities which leads to an increase in bot’s processing time.

To reduce the repetition of such activities we can replace the ‘key’ property of Send Hotkey activity by this —

Syntax to send keystroke multiple times.

#8: Filtering data from DataTable.

While we do have Filter Datatable activity, it does not provide a lot of flexibility in terms of conditions and we cannot query data from multiple DataTables as well.

For the proper implementation, we usually use Linq Query.

Syntax and Example of a Linq Query

The AsEnumerable() function converts the DataTable to an array of Rows and after we have selected the rows we need, CopyToDataTable() convert those back to a DataTable.

#9: If statements in assigns.

If a variable can get multiple values each depending upon a particular condition then the workflow might look like this:

Nested IF Activity.

And this might go on and on. But it’s not a good practice to have nested If activities.

For avoiding the problem of nested IF activities we can use ‘IF’ statements within the ‘value’ property of assign statements.

If statements with Assign Activity.

#10: Formatting String.

While building a dynamic string you must have seen a lot of ‘+’ being used. This approach is good for small strings but is not ideal for larger ones.

Example-

Typical Dynamic Strings.

As we can see Example #1, dealing with short strings is not half bad but things get clumsy when we are talking about Example #2. Here I have formatted the string so that it is a bit easier to understand.

A better approach to form dynamic strings is with the help of String.Format() method

Syntax of String.Format() method

As we can see the text is written in running format and where we required value from any variable we substituted it with a place holder {variable_number}. It tells which variable to pick up from the list of variables mentioned in the end.

So our examples become —

Modified Examples with String.Format() implemented.

#11: Logging type.

This is a really basic one but its importance cannot be overstated. In UiPath we have 5 logging levels. Fatal, Error, Warning, Info and Trace. Each of these levels has its own significance.

When dealing with logs main issue we face is of immense data that is in front of us. If not done properly then logs could look like this —

Logging without setting up the levels.

But If we use proper levels for logging then we can achieve this —

Logging with proper usage of levels.

As it’s clear that we can easily identify the error logs now.

That’s all for now. If you have any more ideas feel free to mention in the comments.

Happy Automation!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store