How to convert DataColumn to Array/List in UiPath

Pradumn Kumar
3 min readSep 11, 2022

--

While dealing with DataTables, we come across scenarios where we need to convert a DataColumn into an Array or List for further usage.

Let’s see how we can achieve it in UiPath through an example...

Example Scenario

Let’s consider a scenario, where we have an input data file (Fig 1) [Columns → Name, Type, Place] and a business config file (Fig 2), where we have the filter criteria for columns [Type, Place]:-

Fig 1:- Data in input excel file
Fig 2:- Filter Criteria.

Our job is to read the data shown in Fig 2 into a DataTable and convert each DataColumn into an Array/List for further use.

Solution

Step 1: Let’s start by reading the BusinessConfig.xlsx file using the workbook “Read Range” activity in UiPath. The output datatable will be stored in variable dt_FilterData

Let's have a look at the current value of the dt_FilterData variable:-

Step 2: Create a variable of type String Array (arr_TypeFilter). Now, let’s convert the Type DataColumn into Array using LINQ and store it in the variable as shown below :

arr_TypeFilter = dt_FilterData.AsEnumerable.Select(Function(x) x.Item("Type").ToString).ToArray

Step 3: We have to create another variable of type String Array (arr_PlaceFilter). Now, let’s convert the Place DataColumn into Array using LINQ and store it in the variable as shown below :

arr_PlaceFilter = dt_FilterData.AsEnumerable.Select(Function(x) x.Item("Place").ToString).ToArray

Result

Let’s print the values stored in the array variables arr_PlaceFilter and arr_TypeFilter. Use below code in the “Log Message” activity.

"Type column -> " + String.Join(",",arr_TypeFilter) + vbNewLine + "Place column -> " + String.Join(",",arr_PlaceFilter)
Fig:- Values stored in both array variables

We just used 2 Assign activities to get the job done! Also, we can substitute the .toArray method with .toList to get the DataColumn in a list variable.

Feel free to Follow me here for more such easy to understand content. I am also available on LinkedIn :-)

Thank you for your time !! See you soon..

--

--

Pradumn Kumar
Pradumn Kumar

Written by Pradumn Kumar

Hey there! I’m a software professional with 5+ yrs of overall experience. I’ve deep interest in tech and geopolitics, which lures me deep into these topics.

No responses yet