DataTable Operations in UiPath

In the following article, I am going to present to you how to work with DataTables in UiPath. Here are the topics that I am going to cover:

First, let’s create a new project called DataTable Operations.

Data Table Operations UiPath project

All operations are performed inside a Sequence. So, let’s add a new sequence and rename it as DataTable Operations.

Create new DataTable

Select the + button to add a new activity to the sequence. You can also press Ctrl+Shift+T. Search for Build Data Table and select the activity.

Create Data Table

To define the columns and rows go on and select DataTable.

DataTable

By default, two columns and two rows are displayed. In this example, I am going to create a Customer DataTable with 3 columns Id, Name and Email address. Also, I am going to add 4 distinct rows. Now let’s configure the columns.

DataTable - Edit column

Because I decided to edit the first column (which was string type), a warning message can be visible at the bottom of the window.

Data Type has changed. All data from this column will be lost.

I am going to do the same for the remaining columns Name and Email.

Edit Column

In the end, the DataTable will look like this:

Build Data Table content

Save everything in a DataTable variable. Go to properties, select the Output DataTable and press Ctrl+K to create a new variable. Name the variable customerDT.

Data Table Operations

Display the DataTable content

Add Output Data Table activity. Search for the activity and add it after the Build Data Table.

Output Data Table

To configure the activity, go to properties and set the Input as customerDT. For the Output create a new variable called customer (String data type).

Output Data Table configuration

To visualize the content of the customer DataTable variable I used a Message Box activity.

Display Data Table

Add new DataRow to DataTable

To perform the first DataTable operation search for Add Data Row activity and add it right after the Build Data Table.

Add Data Row

Go to properties and select ArrayRow. In the new Expression Editor window type the following:

{nothing, “Jerry”, “jerry@mail.com}

The first value of the array is nothing because I have configured the Id column to be auto-incremented. The other values represent the remaining DataTable columns Name and Email.

Also, select customerDT variable as DataTable.

Add Data Row configuration
Display Data Table

Update specific DataRow

To update the value of a DataRow I am going to perform 2 assign operations. First, I am going to identify a specific row using the Select method (where Id = 3), then I am going to pick the Name column and assign it a new value.

customerDR = customerDT.Select(“Id=3”).FirstOrDefault()

customerDR(“Name”) = “The name was recently updated”

Update Data Row
Message box Data Table

Delete/remove specific DataRow

Search for Remove Data Row activity and add it after the Assign activities.

Remove Data Row

Go to properties and set the DataTable as customerDT. Then set the Row. On the new Expression Editor window type the following:

customerDT.Select(“Id=2”).FirstOrDefault()

I am using the same Select method to uniquely identify the row I want to delete.

Remove Data Row configuration

The second row was deleted.

Message Box

Conclusion

UiPath provides out of the box functionalities to manipulate DataTables. From this article, you learned how to create a new DataTable and how to insert default values. Secondly, you learned how to insert a new DataRow to an existing DataTable. Thirdly, you learned how to update the values of a specific DataRow. And the last one, you learned how to delete a DataRow. Now, after you mastered all these operations, you can build powerful and complex automation using DataTables.

Download the solution

Click on the button below to download the source of the demo (DataTable Operations).

Download the UiPath Automation

About Valeriu B

RPA Developer (UiPath certified)

Leave a Reply

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