UiPath Studio is an easy to use tool that helps you quickly build automations. It offers an easy to use, visual drag-and-drop interface. There are many activities that utilize a .NET data structure known as a DataTable, which people unfamiliar with .NET might not have experience with. Here is a cheatsheet to using DataTables in UiPath Studio.
DataTable Basics
MERGE
Accessing data
You can access data in DataTable fields by specifying the row and column. Rows are of type DataRow and are accessible by the DataTable.Rows property. Columns have the type DataColumn are accessable by the DataTable.Columns property.
You will usually want to access every row in a table, and there is a built-in activity for looping through all of the rows in a DataTable named For Each Row. Simply specify the name of the table that you will loop through, and the name of the row variable. Here, we are using table and row.
If you need to loop through the columns, there isn’t an activity built for DataColumns specifically, but it’s easy to do using the For Each activity.
Now that you have a row and column, you can access the data using the syntax row(column)
, which will return whatever is located in that field as an object. Usually, you will be working with this data as text, or a string, so you also call the ToString method, like so: row(column).ToString
. This assumes that you have a DataRow variable named row and a DataColumn variable named column. That won’t always be the case though.
So, lets assume that you have a DataRow variable named row, but you only want to access a specific column. You can do that by calling the row accessor using the column name as a string, like row("ColumnName").ToString
. If you’re reading from an Excel spreadsheet, the column name will be the data in the first row of the sheet.
The last way you can access a field of a DataRow is by index. This is simply passing an integer to the same accessor. For example row(0).ToString
will give you the value of the row at the first column. You want to prefer one of the other two methods, but this works if, for some reason, you only want the first column.
UiPath Activities
In addition to the For Each Row activity, there are many useful built-in activities to help you work with DataTables.
Add Data Column
Add Data Column activity lets you add a new column to an existing DataTable.
Add Data Row
Add Data Row is used to add a row to an existing DataTable.
Build Data Table
Build Data Table allows you to create a new DataTable from nothing, with the specified columns and rows. This is a great activity for testing your workflows.
Clear Data Table
Clear Data Table will remove all rows from a table, but preserve the columns.
Filter Data Table
Filter Data Table lets you specify a filter to grab certain rows from the table.
Generate Data Table
Generate Data Table builds a new DataTable from unstructured data.
Join Data Tables
Join Data Tables lets you combine the rows of two DataTables using a common key. It will attempt to match the tables on the column names in common between the two tables, and the remaining columns will all be available in the resulting DataTable.
Lookup Data Table
Lookup Data Table searches the table for a value in a specified column, and then returns the matching row or value from another specified column.
Merge Data Table
Merge DataTable combines the rows of two DataTables. The tables should have a matching or similar schema, meaning that it should have the same number of columns in the same type in the same order. You can handle differences in schema using the MissingSchemaAction property.
Output Data Table
Output Data Table turns a DataTable into a text string in the csv format. This is useful for debugging, for when you want to view the contents of a DataTable at a certain part of your automation.
Remove Data Column
Remove Data Column removes the specified DataColumn from the DataTable.
Remove Data Row
Remove Data Row removes the specified DataRow from the DataTable.
Remove Duplicate Rows
Remove Duplicate Rows returns a new DataTable with no duplicated rows, so that the data in each row is unique.
Sort Data Table
Sort Data Table sorts a DataTable in a order on the specified DataColumn.