cancel
Showing results for 
Search instead for 
Did you mean: 

How to delete certain rows from a collection ?

SwatiAgrawal
Level 5
Hi,

I have an output collection. This collection can have as many rows. Now my requirement is that, I need only top 6 rows and delete the rest of the rows.
Pls help me achieve this.

Thanks in advance !!

------------------------------
Swati Agrawal
------------------------------
4 REPLIES 4

RaivisLazdāns
Level 4
Hi Swati,

Easy way that you could do this with default actions, would be to create Loop with row copying and merging to some separate collection. Controlling of 6 rows can be done by calculation stage with indexing and simple decision once 6 is reached.
More advanced way would be create separate code stage for copying given row count or doing queries from collection.

Best regards,
Raivis

------------------------------
Raivis Lazdāns
Lead Process analyst/ RPA developer
Europe/Riga
------------------------------

PabloSarabia
Level 11
Hi @Swati Agrawal

You can use some Linq code to achive this.

I attach you to this post the complete object to achieve this.

You need to give to the Action "Select Top" the Collection and the top number that you want to return. As an output, you will get the same collection.

The code looks like this:

dtResult = dt.AsEnumerable().Take((int)ntop).CopyToDataTable();

Where dt is the Collection, and ntop is the number of rows that you want to get.


Hope this helps you. And if this solves the problem, remember mark as the best answer.

See you in the community, bye 🙂




------------------------------
Pablo Sarabia
Architect
Altamira Assets Management
Madrid
------------------------------

LarsVinding
Level 3
Hi,

Another way would be to use the "Copy Rows" action from the Business Object "Utility - Collection Manipulation" if you are absolutely sure that it is always the top 6 rows.
29839.png
You can set the source and output collection to the same collection.

Regards,
Lars

------------------------------
Lars Vinding
Faglig koordinator
Kolding Kommune
Europe/Copenhagen
------------------------------

sahana.mohan
Staff
Staff

Hi Swathi,

as Lars suggested you may use "Copy Rows" action from the Business Object "Utility - Collection Manipulation" or

use "Copy Rows" action from Business Object "Collection". However, Both the actions provide similar functionality, only the input conditions differ. 

29840.png


------------------------------
Sahana Mohan
Solution Designer
Blueprism
------------------------------
Sahana Mohan Lead Software Engineer SS&C Blue Prism