IBM®
Skip to main content
    Country/region select      Terms of use
 
 
   
     Home      Products      Services & solutions      Support & downloads      My account     

developerWorks  >  Lotus  >  Forums & community  >  Best Practice Makes Perfect

Best Practice Makes Perfect

A collaboration with Domino developers about how to do it and how to get it right in Domino

I recently dealt with a question from someone who wanted a way using LotusScript to take a document selection and export each document's data into one of several files, grouped based on the value of the "AssignedTo" field -- so, a separate file for each person documents are assigned to. Having too many files open at a time would be a blocker, so they needed to sort the documents first to write all the data for one file, then move on to the next file.

When faced with such a problem, a lot of people's first instinct seems to be to create a folder that's sorted the way they want, put the documents into it, then read them back out. While this works, it's not going to give the best performance, because there's a lot of overhead involved in removing the old set of documents from the folder, adding new ones, indexing the view, and reading them back out. It's a lot of disk activity and network activity, slowing the server (assuming it's a server database), and it makes the database bigger than it was before, because folder membership is tracked by little records associated with the folder giving the document ID, timestamp, and whether the document was added or removed at that time. This is necessary so that folder membership can replicate. Besides which, we have a problem if there are multiple users working with the same folder, that they may interfere with each other.

It's much more efficient to sort documents in memory, but people don't like having to write extra code to do it.  I'm working on a sample LotusScript library that should make this a lot easier, but in the meantime, here's the approach I suggested. The specific application didn't really require the documents to be sorted -- just grouped into collections that go in to the same export file. So I suggested this approach:

       Dim session As New NotesSession

        Dim ByAssigned List As NotesDocumentCollection
        Dim selected As NotesDocumentCollection
        Dim db As NotesDatabase
        Dim docCur As NotesDocument
        Dim strAssignedTo$
       
        Set db = session.Currentdatabase
        Set selected = db.UnprocessedDocuments
        Set docCur = selected.GetFirstDocument()
        Do Until docCur Is Nothing
                strAssignedTo = docCur.GetItemValue("AssignedTo")(0)
                If Not IsElement(ByAssigned(strAssignedTo)) Then
                        Set ByAssigned(strAssignedTo) = db.CreateDocumentCollection
                End If
                Call ByAssigned(strAssignedTo).AddDocument(docCur)
                Set docCur = selected.Getnextdocument(docCur)
        Loop
       
        ForAll coll In ByAssigned
                strAssignedTo = ListTag(coll)
                ' generate report for person strAssignedTo from documents in coll.
        End ForAll



This isn't perfect; there's probably a limit to the number of documents you can have in a collection, so you maybe could handle larger data sets by defining your own classes (which, as I mentioned, I'm also working on making simpler). But for a limited set of applications, this gets the job done without many lines of code, and without the overhead of working with folders.

Andre Guirard | 22 June 2009 08:51:48 AM ET | Home, Plymouth, MN, USA | Comments (7)

Search this blog 

Disclaimer 

    About IBM Privacy Contact