Data tables are simply data structures that live in memory, and they can hold structured data, and if you recall from any RPA over the course, RPA thrives on structured data; mostly, they're like an Excel spreadsheet that you just can't see.
Open the Data_Table_Example Process in the UiPath Studio and then drag and drop the Sequence inside the designer pane.
Next, add Build Data Table activity inside the Sequence as shown below
Create a new variable for Output Property under the Properties pane
Next, click on the Data Table tab, which is present inside the Build Data Table Activity, and then the Build Data Table wizard opens, which can be of a resizable.
Where you will find two default columns, you can change the name of the column by right-clicking on it.
Close these default columns and then create a new one by clicking on the
+ symbol in the Build Data Table Wizard. Once you click on it, you will find the below wizard.
Next, I am going to create my first column as below
And the second column as shown below
And the Third column as below, in the third column, I am selecting the Data type as System.int16
Next, the column we need for
Email address enter the column name as below and then select the Unique checkbox as below.
So the Data Table is as shown below, you can Add Column or Delete a Column and also you can Rename the Column.
We can go back and edit the column names and types, and not only that, you can click and drag to reorder them within the UI. Again this can only be done in more recent versions of UI path.
And like I said, if you want to edit a column, simply click on this pencil, and you can change the column name, data type, and all the other values that we had access to when we were creating the cell.
And also, it is better to edit the Data Table before entering the data.
We do have the ability to add data rows when we build a data table. Go to the Activities Pane and then search for the word Table, you will find Add Data Row activity.
Insert Add Data Row Activity inside the Sequence and then click on the Add Data Row Activity and enter the Variable name which you have created(
Mydatatable) in the Build Data Table activity, in the DataTable property under Properties Pane.
Before adding the row data, we want to know how many columns are there and their data types by clicking on the Data Table button inside the Build Data Table activity.
As we have Three String data type columns and one Number column in the Data table. Add Data Row activity allows us to pass either the DataRow Object or ArrayRow Object. So I am selecting ArrayRow Object and entering the array as below.
Next, add one more Add Data Row activity and then click on the ArrayRow property and then add one more Row data into the Data Table.
Now, if we run the Sequence, the data table will be created, and two data rows will be added to the Data table.
Now that we've created a data table and added rows to it. Now it's time to loop through those rows and examine cell values. It shouldn't come as much of a surprise to look through our data.
Next, add For Each activity inside the Sequence
Add Mydatatable variable name in the Enter a VB expression and then enter the Log Message activity inside the Body of the For Each Row activity and enter the details as shown below.
"Current User: " + user.Item("First> which is present under Control Activity and then add Log Message activity and copy-paste the details from the Previous Log Message activity as below.
"Current User: " + user.Item("First Name").Tostring+" "+user.Item("Last Name").ToString+" "+user.Item("Age").ToString+" "+user.Item("Email address").ToString
And enter the query
Mydatatable.Select("Age < 50")to print the details of the row where age is less than 50, as shown below.
Deleting Data Table Row:
To delete the Rows from the Data Table first, you need to write the condition in the For Each loop. After adding Row Data to the Data table, add For Each activity inside the Sequence and write the details as shown below.
Next, add If condition activity inside the body of the For Each Activity and then add sequence activity inside the Then condition block as shown below.
Next, add Log Message activity inside the Sequence, and the write the condition as shown below in the Message property under the Properties Pane.
"Deleting Item: "+ user.Item("First Name").Tostring+" "+user.Item("Last Name").ToString+" "+user.Item("Age").ToString+" "+user.Item("Email address").ToString
And then write the condition as shown below in the Condition block
Next, add Remove Data Row activity inside the Sequence in the Then Block and then enter the name of the data table as a user in the Row property for Properties pane.
Next, Save and run the Sequence, after the execution, the row data whose First Name starts from Robert will be deleted.