• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 291
  • Last Modified:

Sorting a collection

does anyone know how I can sort a document collection and use the results of the sort?
Pleeeeaaaassssee help
0
Cuec
Asked:
Cuec
1 Solution
 
Jean Marie GeeraertsApplication EngineerCommented:
Easiest way is to create a folder, define the sorting order in the folder.
Put the collection in the folder with .PutAllInFolder method.
Then read first document from the folder and iterate through the folder using view methods.

A little bit of sample script:

Sub Initialize
   dim session as NotesSession
   dim db as NotesDatabase
   dim coll as NotesDocumentCollection
   dim folder as NotesView

   set db=session.CurrentDatabase
   set coll=db.UnprocessedDocuments
   rem Put the collection in a sorted folder, set sort options in the folder
   call coll.PutAllInFolder("SortedFolder")
   rem Get a reference to the folder
   set folder=db.GetView("SortedFolder")
   rem walk through the documents in the folder one by one
   dim doc as NotesDocument
   set doc=folder.GetFirstDocument
   do while not doc is nothing
      rem Process document and then get next document
      set doc=folder.GetNextDocument(doc)
   loop
End Sub

Hope this gets you on your way, if not just ask for further info.

Regards,
JM
0
 
tritankaCommented:
As a second option, put all the docs in an array of type NotesDocument then use a quicksort algorithm to sort the array.

This really depends on how many documents you are talking about.

Jerrith's solution seems more elegant and will probably result in less over the wire traffic when working with a server based database.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now