Manage Learn to apply best practices and optimize your operations.

Process Selected Documents in the Order They Are Sorted in a View

If you have several documents in a view, and you want to perform and action on a select few of them, in the order they appear in the view, what is the best way to go about it?

In the R4 world an agent would process a document collection in the order of their UNID, not in the order they appeared in a view. In R5, the ViewEntry class was added that would allow you to process documents in the order they appeared in a view, but what if you do not want to process ALL the documents in the view, how do you process just a collection of selected documents?

A technique I use a lot is to create a hidden folder named "temp", that is designed with the first column sorted in the same order as the view you are selecting documents from. (example: name or date) Then when the user selects the document this wish to perform some action on, the documents are moved into this folder, they are all placed in a collection, then the collection is acted upon in sorted order. When the agent completes, the document are removed from the hidden folder.

Sub Initialize
' Create a document collection from selected docs
' Move doc collection to a folder
' Process items in the folder as a view entry
' Remove from folder

Dim ws As New NotesUIWorkspace
Dim session As New NotesSession

Set db = session.CurrentDatabase
If (db Is Nothing) Then Goto endofsub
Set dc = db.UnprocessedDocuments ' gets a handle on the documents you selected
Call dc.PutAllInFolder( "temp" ) ' moves those selected documents into a folder
Set view = db.GetView("temp")
Set vc = view.AllEntries ' gets a handle on all the documents in the folder
Set entry = vc.GetFirstEntry()
Set doc = entry.Document

' place the code for the action you want to take on each document here
Set entry = vc.GetNextEntry(entry)
If Not (entry Is Nothing) Then
Set doc = entry.Document
End If

' place any wrap up stuff here
Call dc.RemoveAllFromFolder( "temp" )

End Sub

Dig Deeper on Domino Resources - Part 2



  • Favorite iSeries cheat sheets

    Here you'll find a collection of valuable cheat sheets gathered from across the iSeries/ community. These cheat ...

  • HTML cheat sheet

    This is a really cool cheat sheet if you're looking to learn more about HTML. You'll find just about everything you every wanted ...

  • Carol Woodbury: Security

    Carol Woodbury