Add Data Row to DataTable - enumeration operation might not execute

I have a DataTable that stores info from a data scrape, but would like to add an extra column and input data into existing rows into the new column after the data scrape.

This is conditional, so if the condition is met it should add the new information to the current row in the new column. If the condition is not met, it ignores it and continues.

I have the IF statement working and have managed to get the column to add, but the problem I have is with the add data row.

At the moment the Add Data Row activity uses ArrayRow to populate the row – e.g {“”,“”,“”,“”,Variable} (‘Variable’ contains the value, and is in the position of the new data column added.) All other columns should be ignored, hence the double quotes(I have done a DTOut to check).

This is within a for each, because it’s iterating through each record in the table, but I have read you shouldn’t put Add Data Row within a For each loop, but can’t work out how to do it otherwise.

The Error i get after the Add Data Row activity is: Collection was modified; enumeration operation might not execute.

I’ve figured out that i think i need to append to the row somehow, as I moved the Add Data Row outside the For Each and it worked, but the value of the new column, was on a new row on it’s own, with the other cols blank - which is what I guess I told it to do!

Any ideas on the equivalent of an ‘Append Data Row’

Hi @aod,
If I understand correctly you don’t want to add rows to the existing datatable, but add a value in the last column, based on a condition. Is that correct? (if not please share a screenshot or your workflow)
So to add a value in the last column, you should loop with a “for each row” on the datatable(after you added a column with the “Add Data Column” activity).
Then inside the “For Each Row”:
Add you “if” condition
assign row(4) (assuming you have 5 columns) to the new value with the “Assign” activity

This should be enough.
Use the “Output datatable” and a write line activity to check that the data is as expected

That sounds about right, can you hep with the syntax i need (assume in an assign activity?)

It would actually be the current row of the for each iteration, assuming the condition is met in the IF statement, but yes the last column in the datatable (which was added before the for each and IF)

What do you need to know about the syntax?
In the “for each row”, “row” is the current row. So then to assign you either choose “row(column number)” for example row(4) or “row(column name”).

For example if you have 10 rows,
for the first iteration “row(4)” means 5th column of first row
for the second iteration “row(4)” means 5th column of the second row
… and so on

Thanks by syntax i mean, what do i type and where?

You say assign, do you mean I need an Assign activity, or do you mean ‘assign’ something to something?
Where do I chose "row(column number), or in your example row(4) or “row(column name”).

Where does this text go in the workflow?

Yes “Assign” activity. After you added a column with the “Add Data Column” activity, you should have something like in the image:

Here I am assigning to “row(2)”, which means the third column of the current row

1 Like

OK thanks, that makes sense - i do actually already have something like this set up already, it was just knowing how and where to add the row, and I think the assign activity should sort it. I’ll give it a go

Excellent that works perfectly, many thanks! Much more simple than I thought :slight_smile: