How to add a row of data inside a Data Table using a list of values

I wish to add a listOfValues.ToArray() inside multiple columns such that each value of the list occupies same column index as the value occupies inside the original list.

There doesn’t seem to be a spread operator or functionality I can use to spread the values into my columns.

I’ve tried to use Add Data Row activity. My current code on the ArrayRow field looks like so:
new Object() listOfValues.ToArray()

This how ever brings up and error since it tries to put the listOfValues inside single cell instead of multiple cells. (each cell has been set to have data type of Int32) so UiPath complains that I cannot add Int32 inside type Int32.

Is there a pretty way to do this?

PS. I already gave up adding each value one by one, because creating empty datarow which would automatically resize to each additional column added doesn’t seem possible even though I think it should and I have a dynamic amount of columns created. It is probably possible to loop over the columns again, but that is just… Not pretty or easy to read from the automation workflow.

Hi @Henri_Johansson -

list.ToArray is working fine. you can check the attached code. If anything else you are looking at can you explain with some code what exactly you are trying out?

Sample2.xaml (14.3 KB)

YourList.Cast(of Object).ToArray

ensure that the item count of the list is matching the data columns count

@Henri_Johansson

Listvar.ToArray should do the job…unless you have a list of array of integers

can you confirm your variable types

cheers

I confirm that my list and column type are both set to be Int32.

Are you hinting that the spreading of the values functionality has not been done for type T, but for type Object or Enumerable instead? I would expect a function to work the same with array of the value T what ever the T would happen to be.

What error do you get when you use add data row activity
With input as listVariable.toarray and your data table variable

Assuming no of items in list is same as no of columns in table

@Henri_Johansson

If the defined T is an array of integer then it would throw similar error…

As your datatype would be array of array od integers and expected is array of integer…in first case T is an array and in second case t is integer

Cheers