Hi
Welcome to uipath community
—hope these steps would help you resolve this
—use READ CSV FIle Activity and pass the file path of csv as input
—then use FOR EACH activity and pass the able variable dt as input like this dt.Rows
—inside the loop use IF condition and set the condition we want
—if it passes it will go to THEN part where we can use ADD DATAROW activity and mention the datatable dt as input for datatable property and in Datarow property mention as dt.NewRow
It is not a good idea to modify a collection while you are looping through it. Instead, what you should do is loop through your CSV as Palaniyappan suggested, and, if the condition is met, add a new row to a different DataTable. This will also ensure that you will at some point stop as you could potentially run into an infinite loop if you keep adding new rows that meet the condition.
aaah …i m sorry for that
both FOR EACH ROW or FOR EACH wont work as we wont be able to add new datarow to a datatble which is actaully under iteration
so we can use while loop like this counter < dt.Rows.Count
where counter is a variable of type int32 with default value as 0 defined in the variable panel
–inside the while loop use a IF condition like this dt.Rows(Counter)(“yourcolumnname”).ToString.Contains(“your keyword”)
if true it will go to THEN part where we can use ADD DATAROW activity with datatable as dt and DataRow as dt.NewRow
This still is not suggestible. All you did is try to circumvent the error that is rightly generated for attempting to add to a collection while looping through it. It is not a good idea to do this, instead a new DataTable should be populated unless the user is absolutely certain that they want the added rows to be checked as well.
Hey @Palaniyappan
I followed the same steps, but got a error message.
Error message
Source: Add data row
Message: Object reference not set to an instance of an object.
Exception Type: System.NullReferenceException
An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:
System.NullReferenceException: Object reference not set to an instance of an object.
at UiPath.Core.Activities.AddDataRow.Execute(CodeActivityContext context)
at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.ActivityInstance.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)
As @dmccammond had warned, if i use the same datatable then it enters a infinite loop!
and if a new datatable is given then the above error message is displayed.
Can you please guide me with the add data row activity.
Thanks in advanvce!
Is there any approach where we could convert each column into a table and match the values in the other columns and add in new row to that particular table??