Deleting rows in a Data Table

Hi everyone,

image

I want to delete rows in the above data table if row date is equal to 4/15/2022. Can someone please share a solution how I can accomplish this? Thank you.

Hello,

Inside for each row in datatable use ‘Remove Data Row’ activity with following customized properties

For each row in datatable activity
CurrentRow in userdatatable

{
If Activity ( CurrentRow(“Date”) = “dd/mm/yyyy”)
{
Delete Row activity (property)->
Row : CurrentRow
Datatable : userdatatable
}
}

Best Regards,
Sagar Rana

Hi @RPA_Path,

I would recommend you use the Filter Datatable Activity. Compare dates and where Date column is equal to your comparision, choose to remove that row. Finally, save the filtered datatable to the same variable as your input datatable. Essentially, you are filtering your input datatable.

2 Likes

Except you can’t do that because you can’t remove rows from the same datatable you are actively looping through.

Thank you for pointing that out, I will keep that in mind for future references.

Then, would it be best to save the row in a variable then delete it outside of the loop?

If you do not want to use the filter method, then you have to make a new empty datatable (also can be a clone of your datatable that way you retain the column name and types) and move/add row each rows which DOES NOT match your condition within a for loop to the cloned datatable.

But this approach is not so elegant in my view.

When there is a default activity, I recommend you use it. In your case that is Filter Data Table activity.

1 Like

Thank you.

Just use Filter Datatable.

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