Unexpected Row Distribution

I was recently working on a UiPath automation that required creating a structured report from various data sources. The process involved building a DataTable with three columns: Name, Age, and Job.

My initial approach was to use the DataTable.NewRow method (How to add new value (data row) in existing Datatable? - Help - UiPath Community Forum) to create rows and populate them. However, I encountered an unexpected issue with how the data was being inserted into the table.

The Implementation

I created a workflow that involved first creating a new DataTable with three columns: Name, Age, and Job. For the first row, I used the ArrayRow approach and provided only the name “John Smith”. Then, I attempted to add Age and Job information using the DataTable.NewRow method (Age and Job has its own of DataRow), thinking it would update the existing row.

The Unexpected Result

When I ran the automation, the output DataTable looked like this:

image

The Name value was correctly inserted in the first row of column A, but the Age and Job values were placed in the second row under columns B and C. This wasn’t what I intended - I wanted all three values to appear in the same row.

@AZNI_SYAZWANI,

Why not using single approach, using Add data row or using Datatable.NewRow?

Any activity you executed from above two will add a row to datatable.

Hi @AZNI_SYAZWANI ,
Can you share the flow how you developed. something is wrong in the code i can check and update you.

Regards,
Arivu

I want to use ArrayRow for {var1, var2, var3} and then add var4 and var5 because they are from different sequences. I am not sure whether DataRow can also handle {var1, var2, var3} in the same way.

@AZNI_SYAZWANI,

In this case you can pass whatever values you have to the sequence where all values will be available and add the data row there once.




I want to use ArrayRow for {var1, var2, var3} and later add var4 and var5 from different sequences. However, as shown in the attached image, I’m currently using only one variable for ArrayRow, while the real RPA setup has multiple variables.

ArrayRow seems better for homogeneous data, but I’m unsure if DataRow can maintain the sequence of var1, var2, and var3, which is crucial for my report. Thank you!

@AZNI_SYAZWANI,

Instead of having multiple add data row, use an array to store all the data and use a add data row activity to add row using array.

@AZNI_SYAZWANI

  1. Use assign activity with datajam.rows(datajam.Rowcount-1)("Age") = "Age value" this way a new row is not created but the data is assigned to the last possible row which is the new row added with add data row in your case
  2. Use array store the values and at last use add datarow with passing the array

Cheers

I added the first Add Data Row activity to temporarily store email-extracted data in the DataTable for running two sequences: Sequence A and Sequence B. In Sequence A, I record the time of ID deletion, and in Sequence B, I save the deletion time for System B. Since multiple IDs need processing, I use multiple Add Data Row activities.

Please correct me if my understanding is wrong, as I’m still new to UiPath.

Hi @AZNI_SYAZWANI

Please note that - Whenever you use Add Data Row Activity, it will always add a row and update the value. If you want to update on the same line - Kindly follow below approach

Step 1: Create a variable (ArrayString) of type Array of String and initialize the variable as provided in the below screenshot. Variable type is Array (Of String). Default value is important

Step 2: Create a data table in the expected format and columns using Build Data table

Step 3: This is important
instead of adding data row directly, our method should be to add details to above Array of string variable. Use below expression in assign activity for the same. Values same as what you used while adding data row to data table. I have used value as Newvalue here in the below screenshot

Step 4: Instead of second add data row activity, use the same for different values. Idea is to complete the array of string variable matching with the data columns in data table and add this array at the end

Step 5: Continue as long as you get all the values to a single data row in the data table

Step 6: Add this as a data row in the data table using below activity

This way - you configure all the values to first row in an array and use add data row only one time.

For reference: Full workflow

Hope it helps. Happy Automation

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.