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â).
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