Thursday 3 April 2008

Working out what folder any given document is in if FolderReferences is not switched on

Here is a bit of code from the Lotus Notes Support site which like all
simple things is only simple when you see it done :-). The gurus amongst you
probably know this already but for me it was "oooooooo right" moment.

Here is the code for a selected docs agent


Dim session As New notessession
Dim db As notesdatabase
Dim doc As notesdocument
Dim doc2 As notesdocument
Dim view As notesview
Dim noteid1 As String
Dim noteid2 As String
Dim item As notesitem
Dim collection As notesdocumentcollection
Set db=session.CurrentDatabase
Set collection=db.UnprocessedDocuments
Set doc=collection.getfirstdocument
noteid1=doc.NoteID
Forall v In db.Views

If v.isfolder Then
Set doc2=v.GetFirstDocument
While Not doc2 Is Nothing
noteid2=doc2.NoteID
If noteid1=noteid2 Then
Messagebox v.name
End If
Set doc2=v.getnextdocument(doc2)
Wend
End If

End Forall

5 comments:

Anonymous said...

Bob has blogged about a nice alternative method to accomplish this.

Unknown said...

@Jens
Cool!
I like Bob's way too .. i wonder which is faster ?? at a guess I would say bob's.

Steve

Julian Robichaux said...

Also, iterating through a NotesViewEntryCollection should be way faster than iterating through a NotesView in that situation (since you only need the NoteID). I'd be curious to see some speed tests.

Unknown said...

@Julian - I did some down and dirty testing and these were the results.

Here are the results

Test done on Std Mail file with 20 Folders each containing 50 messages (1000 messages in total)
All agents run on the All Docs view.

Agent #1 (IBM tech Note)
Outside Loop => UnprocessedDocuments in ALL Docs
Inside Loop 1 => Every folder in DB
Inside Loop 2 => Every Doc in Current Folder until match on ID (loop exited on find)
Total time 4126 Secs
Approx 4.1 secs per doc

Agent #2 (Bob Balaban)
Outside Loop => UnprocessedDocuments in ALL Docs
Inside Loop 1 => For Every folder in DB create and test for sucessful ViewNav creation using CreateViewNavFrom
Total time => 2.804 Secs
Approx 2.8 secs per doc

Agent #3 (Julian)
Outside Loop => UnprocessedDocuments in ALL Docs
Inside Loop 1 => Every folder in DB
Inside Loop 2 => Every VE in current Folder until match on ID (Loop exited on find)
Total Time = 3227
Approx time 3.2 sec per doc.

Julian Robichaux said...

Excellent. We have a winner, and Bob's your uncle! Balaban, that is.

Disqus for Domi-No-Yes-Maybe