For example : Here I need to delete rows contain “bbb” and “ccc”
The output should contain only rows with “aaa”
Hi @sree 1855 ,
If you are using the Data Table package, there is an option called Delete row for this requirement. You just need to pass the Data Table variable and the Row Index number. Since you need to clear 2 different rows, you can repeat this process 2 times and provide the required Row index.
Note: Row index is starting from 0.
I hope this will help.
I actually have the same question - write now I’m looping through each datatable row, evaluating one of the fields from my tablerow variable, and if the condition is met, calling ‘Delete Row’ - however I’m unsure of how to provide the Delete Row action with the index of that current data row that just passed the condition (which might be the loop counter - 1 since I believe the table rows are zero indexed). Thanks.
Hi @JustinK ,
You can use a counter variable inside the loop and an If condition to check whether the row is fulfilling your criteria or not and use the Delete Row action if not. You can pass the counter variable there as the row index.
I hope you get the logic.
I think the issue with deleting as you loop is that the index changes so your counter can get off. For example, if I have 20 rows and your counting (starting with a counter at 0) and I find my criteria for a delete at “counter row 4” and I delete that row, I should NOT advance the counter because my table is now one row less than it was before the delete.
If I advance the counter after a delete, when I find another row to delete and I use the counter as the row number, I will actually delete the row AFTER the one I want to delete.
So, either advance the counter only when you DO NOT delete the row, or start the loop over (and the counter) each time you delete a row.
Hi @JustinK ,
You can test with NOT ADVANCING the counter when you delete the row as in like : If row is deleted then decrement the counter by 1 and it will automatically increment at the end of the loop.
I think in above way you don’t have to start over the loop or counter.
@Zaid Chougle I’ve been trying to do this using the method of not advancing the counter but there seems to be an issue when you delete a row while looping. I’m not sure where the ‘curser’ is in the loop after you delete. I think may actually be moving to the next row. I’ve got a use case where I need to remove every row that has a certain value and I’m getting unexpected results, like it’s removing the wrong rows on subsequent loops.
Below I’m looping the data table and only removing certain rows and only incrementing the iRow number variable when we don’t remove a row. But as it progresses it leaves behind some rows that it should have removed and removes others that it should not.
Lines 28 down I’m just re-looping and outputting to a log file to check the data.
Can anyone confirm the behavior of the loop when you remove a row? Like if the very first row is removed from a data table while looping are you still on row 0 or are you now on row 1?
So I checked the values of the current row before and after the deletion and what’s happening is that if you delete any row the rows are moved UP but the looping internal counter DOES NOT change so it essentially skips a row. Example:
Same hold for items removed in the middle of the table:
So it seems the only way to delete the correct rows in a loop is to exit the loop each time you remove a row and start over. OR create a list of indexes that need to be removed and remove them in reverse order in another loop so the indexes do not get off.
Create a new empty table and add desired rows to it. Overwrite original table with this table if needed.
This avoids index and other tracking and is simple to understand.
filtered_table= empty tableLoop over table_to_be_filtered if current_row matches deletion criteria continueadd current_row to Filtered_tableEnd Loop
@Sumit.K7 I’m actually trying that with the rows that are being removed (inserting them into a blank table for later use). The issue with that is that it seems you can no longer refer to the column indexes from a row record when you loop that table. It’s really strange behavior.
Here’s what I’m doing:
Given this behavior I DO NOT want to try this with my main table if I can’t get the data out of it! Any suggestions?
@Sumit.K7 what it looks like is happening is when I use Insert Row with a record object it only creates ONE column in the target blank table instead of the 9 columns from the record object. I’ve confirmed this by using Get Total Columns and Get Totals Rows after inserting a row. I’m starting to think these table objects are pretty useless when it comes to adding records, rows, columns etc.
@Sumit.K7 ok I was able to use your method BUT I had to first use the Assign command to create the columns needed in the target table:
This successfully adds rows to table 2 from table 1 with the same columns.
Esto es lo que me funciono, saludos a todos
Already have an account? Login
Enter your username or e-mail address. We'll send you an e-mail with instructions to reset your password.
Sorry, we're still checking this file's contents to make sure it's safe to download. Please try again in a few minutes.
Sorry, our virus scanner detected that this file isn't safe to download.