Manipulate Tables
The example below explains how to build a table, merge it, sort the data and remove duplicates. It uses activities such as Merge Data Table, Sort Data Table, and Remove Duplicate Rows. You can find these activities in the UiPath.System.Activities package.
This is how the automation process can be built:
-
Open Studio and create a new Process.
-
Drag a Sequence container in the Workflow Designer.
-
Create the following variables:
Variable Name Variable Type Default Value DT1DataTable DT2DataTable DataTableStringString
-
-
Drag a Build Data Table activity inside the Sequence container.
- In the Properties panel, add the variable
DT1in the DataTable field.
- In the Properties panel, add the variable
-
Click the DataTable button from the Build Data Table activity.
- Click the Add Column button and add a new column.
- Click the Edit Column button from the first column and add the value
Namein the ColumnName field. - Select the String option from the Data Type drop-down list.
- Select the check box for the Allow Null option.
- Add the value
-1in the Max Length field. - Click the OK option for closing the window.
- Click the Edit Column button from the second column and add the value
Surnamein the ColumnName field. - Select the String option from the Data Type drop-down list.
- Select the check box for the Allow Null option.
- Add the value
-1in the Max Length field. - Click the OK option for closing the window.
- Click the Edit Column button from the third column and add the value
Gradein the ColumnName field. - Select the Int32 option from the Data Type drop-down list.
- Select the check box for the Allow Null option.
- Add the value
-1in the Max Length field. - Fill in the fields with names, surnames and grades.
- Click the OK button for closing the window.
- Click the OK button again.
- Here is how the Build Data Table should look:

-
Drag another Build Data Table activity below the previous Build Data Table activity.
- In the Properties panel, add the variable
DT2in the DataTable field.
- In the Properties panel, add the variable
-
Click the DataTable button from the Build Data Table activity.
- Click the Add Column button and add a new column.
- Add the value
Namein the ColumnName field. - Select the String option from the Data Type drop-down list.
- Select the check box for the Allow Null option.
- Add the value
-1in the Max Length field. - Click the OK option for closing the window.
- Click the Edit Column button from the second column and add the value
Surnamein the ColumnName field. - Select the String option from the Data Type drop-down list.
- Select the check box for the Allow Null option.
- Add the value
-1in the Max Length field. - Click the OK option for closing the window.
- Click the Edit Column button from the third column and add the value
Gradein the ColumnName field. - Select the Int32 option from the Data Type drop-down list.
- Select the check box for the Allow Null option.
- Add the value
-1in the Max Length field. - Fill in the fields with names, surnames and grades.
- Click the OK button for closing the window.
- Click the OK button again.
- Here is how the Build Data Table should look:

-
Place a new Sequence container below the Build Data Table activity and name it Merge.
-
Drag a Merge Data Table activity inside the Merge container.
- In the Properties panel, add the variable
DT1in the Destination field. - Select the Add option from the MissingSchemaAction drop-down list.
- Add the variable
DT2in the Source field.
- In the Properties panel, add the variable
-
Drag an Output Data Table activity below the Merge Data Table activity.
- In the Properties panel, add the variable
DT1in the DataTable field. - Add the variable
DataTableStringin the Text field.
- In the Properties panel, add the variable
-
Place a Write Line activity under the Output Data Table activity.
- Add the expression
"Merged DataTable:"in the Text field.
- Add the expression
-
Place another Write Line activity under the previous one.
- Add the variable
DataTableStringin the Text field.
- Add the variable
-
Drag a new Sequence container and place it below the Merge container.
- In the Properties panel, add the value
Sort Descending by Gradein the DisplayName field.
- In the Properties panel, add the value
-
Drag a Sort Data Table activity inside the Sort Descending by Grade container.
- In the Properties panel, add the variable
DT1in the DataTable field. - Add the variable
DT1in the DataTable field. - Add the value
"Grade"in the Name field. - Select the Descending option from the Order drop-down list.
- In the Properties panel, add the variable
-
Drag an Output Data Table activity below the Sort Data Table activity.
- In the Properties panel, add the variable
DT1in the DataTable field. - Add the variable
DataTableStringin the Text field.
- In the Properties panel, add the variable
-
Place a Write Line activity under the Output Data Table activity.
- Add the expression
"Sorted DataTable:"in the Text field.
- Add the expression
-
Place a Write Line activity below the previous one.
- Add the variable
DataTableStringin the Text field.
- Add the variable
-
Drag a new Sequence container and place it below the Sort Descending by Grade container.
- In the Properties panel, add the value
Remove Duplicatesin the DisplayName field.
- In the Properties panel, add the value
-
Place a Remove Duplicate Rows activity inside the Remove Duplicates container.
- In the Properties panel, add the variable
DT1in the DataTable field. - Add the variable
DT1in the DataTable field.
- In the Properties panel, add the variable
-
Drag an Output Data Table activity below the Remove Duplicate Rows activity.
- In the Properties panel, add the variable
DT1in the DataTable field. - Add the variable
DataTableStringin the Text field.
- In the Properties panel, add the variable
-
Place a Write Line activity under the Output Data Table activity.
- Add the expression
"Remove Duplicates DataTable:"in the Text field.
- Add the expression
-
Place a Write Line activity below the previous one.
- Add the variable
DataTableStringin the Text field. - This is how the workflow should look:

- Add the variable
-
Run the process. The robot builds a table, merges it, sorts the data and removes the duplicates.
Here you can download an example.