Create copy of datarow in new datatable

Hello

I am trying to create a new row using DataRow.Copy to copy the data from an existing row.
However after updating dependencies, I am experiencing the error below:

How do I copy an existing row with all its values to a new row without these two having dependency of each other?

Regards
Soren

Could you please let us know the versions of the packages?

It seems to be

UiPath.Excel.Activities

when upgrading from version 2.23.4 to 2.23.5 or higher.

Regards
Soren

Oops!
Hopefully this will be fixed soon. In the meantime you can workaround this way(I am sure you know this already!):

I am trying to understand the use case.

Is this like this video below, where I import each row from the oldDT to a newDT?

Hello @loginerror

The flow is as shown below.

The use case is that I am checking if a student is below 18 years of age.
If this condition is met, then I lookup their guardian in another datatable and make a copy of the student’s row, replace their personal identification number with the one from their guardian, and inject this row into the original datatable.

Regards
Soren

A quick workflow:

image

image

image

image

dtStudent.Columns("SID").Expression = dtStudent.Columns("GID").ColumnName

dtStudent = dtStudent.DefaultView.ToTable

Result:
image

Caveat: All students need to have a Guardian.

Hello @sudster

The datatable with guardians contains 25+ columns that I dont need.
I simply need a new line in the students datatable, with the excact same values as the student has, and then simply replace a single value in a single column.

Regards
Soren

Adding a filter step before the join would do this for you.
image

Don’t you have all students in the DT already?

Yes I do :slight_smile:
But as stated initially I need a copy of an existing row.

In the example below, the rows 2,3 and 6 represent rows injected with same values, but different PIN (for guardians).

As an example:

Student Name Student Age Student Address City Student PIN
John Doe 17 Test Road 1 Detroit 11223344
John Doe 17 Test Road 1 Detroit 11111111
John Doe 17 Test Road 1 Detroit 22222222
Emily Johnson 18 Test Boulevard 7 Kansas 12341234
Steward Anderson 15 Test Drive 19 New York 12121212
Steward Anderson 15 Test Drive 19 New York 44448888

I need to “letter braid” (dont know if thats the right word) in Microsoft Word afterwards.
We find reciepients based on PIN, so in the use case shown, the guardians would recieve the excact same letter as the students, as the values are the same.
Only difference is the PIN which has changed (and which marks the reciever).

Regards
Soren

Ok, now I understand the requirement for the duplicate row. :grinning:

It’s called mail merge.

How do you find the guardian for a student? What is the common key?

You don’t need to copy the row nor iterate through the DT to achieve the result.
image

Have you tested to add the new row and then retrieve it instead?

dtrw_NewRow = dt_DT1.AsEnumerable.Last

image

Hello @sudster

In this particular case I need to copy the row.

A system that is used in the process afterwards needs 1 column for PIN to succesfully register the recipients and send to these people’s digital mailbox (all danish citizens have these).
And for the letters to contain the excact same info, the rest of the columns should just contain the same info as the student at hand.

I know how to lookup the datatable with guardians to find the correct one(s) (PIN is key here), but that is not the problem here.
The excact case here, is that I need to copy a row to 1-4 (depending on number of guardians) others, and just replace a single value in this row (containing 20+ other information).

Regards
Soren

Hello @ptrobot

Wouldn’t this simply copy the last row of the datatable?

I am iterating anywhere between a couple to several hundred rows.
Just as an example, it might be that I need 2 copies of row 73, 1 copy of row 103 and 3 copies of row 105.

Regards
Soren

No, this will make a copy of the CurrentRow and put the copy at the end of dt_DT1. If you need more than one copy, just repeat the sequence (add data row and retrieve).

1 Like

Yes you’ll get a copy of the Student row for each Guardian, without actually copying the row. For example, if a Student has 5 Guardians, there will be 5 rows for that Student.

Maybe, if you could please upload anonymised sample data (Spreadsheet for Students and Guardians tables), I can make a workflow for you.

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