I am trying to add data row in for each row activity with if condition. but I am getting the error: Collection was modified enumeration operation might not execute
Version: 2021.10.4 community version
I am trying to add data row in for each row activity with if condition. but I am getting the error: Collection was modified enumeration operation might not execute
Version: 2021.10.4 community version
Hi Muralikrishna,
Yeah, you won’t be able to change the content of the entity your are currently looping through.
If you need to do this, I recommend you add this data to a copy of your datatable, with the same structure but empty, and after the loop you cange use the merge datatable acitivity to get all that data together in one datatable.
Just iterate over John.Copy and keep John as datatable for adding rows
You are right, you can copy structure and content and than do what you said, it’s easier than merging afterwards.
Great thank you!!! How about adding specific rows with contains few values in columns in if condition
I need to add rows which contain only “AWS”, “Python” and “Power BI” in Cost Center column.
Currently below it is adding all of them
maybe you can help us with more details on your case. it looks like following:
It seems to us, that now rows are duplicated to John.
Maybe we do have a wrong interpretation and you can elaborate more on this. Thanks
Sure Peter.
I have a mastersheet from which I am filtering data table as John.
I am using for each row in johncopy, putting if condition with some coloumn values that I need as shown in image above
Adding datarows to John again but i can write in different table also
Then write range John in different sheet/excel and send an email to the person who owns those column values(basically project owner of those skills).
I hope I am clear. Thank you
Great
Hope the below steps would help you resolve this
Let’s take you have the datatable named John
Now use a assign activity like this
John_tempdt = John.Copy
Where John_tempdt is a variable of type System.Data.Datatable defined in variable panel with default value as New System.Data.Datatable
arr_costcenter = {“AWS”, “PYTHON”, “POWER BI”}
Where arr_costcenter is a variable of type Array of String defined in variable panel
Now use a FOR EACH ROW activity and pass John_tempdt as input
Inside the loop use a IF condition like this
arr_costcenter.Contains(CurrentRow(“Cost Center”).ToString.ToUpper)
If true it goes to THEN block where use a ADD DATAROW activity and mention property like
Arrayrow = CurrentRow.ItemArray
Datatable = John
Cheers @Muralikrishna_Basani
Is there any further queries on this topic
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.