How to remove last row from a collection?

AshutoshMahale

New Member
Hello All,

I have a situation where I have to confirm a logic and if it's true, then I will have to remove the last row in a collection. Is there any provision in BP for doing the same?

PS: I have used the Remove row action in Collections VBO, but its removing the 1st row of collection instead of last row.
 

VJR

Well-Known Member
Hi AshutoshMahale,

The Remove Row works when the loop on the collection is iterating on that row. So when the loop reaches the last row and then if you use the Remove Row action it will delete the last row.
 

AshutoshMahale

New Member
Hi AshutoshMahale,

The Remove Row works when the loop on the collection is iterating on that row. So when the loop reaches the last row and then if you use the Remove Row action it will delete the last row.
@VJR Thanks for the reply!! Is there any way to delete the 2nd last row? I also have a condition where I have to compare last 2 rows of collection, and if they are similar then have to delete the 2nd last row, keeping the latest row intact.
 

VJR

Well-Known Member
Is there any way to delete the 2nd last row?
This is applicable to any row of the collection.

The Remove Row works when the loop on the collection is iterating on that row.

Have you checked what happens when the loop reaches the 2nd last row and then it is deleted because it is similar to the last row?
 

AshutoshMahale

New Member
This is applicable to any row of the collection.

The Remove Row works when the loop on the collection is iterating on that row.

Have you checked what happens when the loop reaches the 2nd last row and then it is deleted because it is similar to the last row?
I am not able to delete the 2nd last row because when the loop reaches last row, it cannot access the 2nd last row for deletion as the current row in progress is the last one. Is there any functionality in BP where I can delete the 2nd last row after comparing it to the last row at that instance?
 

VJR

Well-Known Member
Is there any functionality in BP where I can delete the 2nd last row after comparing it to the last row at that instance?
Hi AshutoshMahale,

There is no direct functionality but you can apply your own logic to do so.
- Assume your original collection is Collection 1
- Use 'Count Rows' from the Collections VBO. Get it in a Data Item say TotalRows.
- Use 'Copy Rows' of Utility Collection where you need to pass the row index number. This would be TotalRows - 1 for the 2nd last row. This will be copied into another collection - Collection 2. This is a single direct action and no loop is involved here.
I believe the indexes for the collection row start from 0 so take care on that.
- Do the same thing for the last row this time by passing the index number as TotalRows. Copy Rows will overwrite any previous rows in the output Collection 2. So either copy to a new Collection 3 Or Append to Collection 2.
- Perform the comparison between these two rows depending on whether it is a same or different collection generated in the above step.
Here you can determine which row you want to keep or delete. Lets say you want to delete the 2nd last row.
- Now loop through the original Collection 1. Reach the 2nd last row using a Counter variable. When the Counter will reach TotalRows-1, it is the 2nd last row and now run the Delete action.

If you would not like to go with the ready made available actions as above then you will have to write a Customised Code stage to interact with the Collection and delete the desired row.
 

VJR

Well-Known Member
Hi AshutoshMahale,

That's a good logic, shared by DanielTorres.
You can use the same index number logic on the reversed collection.
 

VJR

Well-Known Member
each time appending a row in that collection
Hi AshutoshMahale,

There is no appending to collection involved in the logic if your main task is to only compare the last two rows and do the deletion.
- Reverse the Collection (Lets call it OriginalCollection)
- Copy first row to another collection (TempCollection) - single action
- By looping go to the 2nd row (when counter reaches 2)
- Do your row comparison between this 2nd row (ie; current row) of OriginalCollection and that 1 row in the TempCollection
- If you want to Delete then now use Delete action which will delete the 2nd row of OriginalCollection which is ideally your 2nd last row
- Reverse back the OriginalCollection
Does Bp become slow when it reverses the collection of 40K rows?
Does this make sense to what you want to achieve?
 

AshutoshMahale

New Member
@VJR My task is as below:
1) Keep on appending a row in collection from a separate collection
2) Compare the latest added row data with the 2nd last row
3) If its found as same then delete the 2nd last row
4) If not then leave as it is
5) Repeat steps 1-4 again

Reversing the collection which would have 40K+ rows twice every time is not turning out to be time efficient for me. Can you suggest anything else, except custom code?
 
Top