Getting ’selected documents’ in a LS agent
Posted by Theo Heselmans on November 8th, 2008
When you need to 'collect' the selected documents in a LotusScript agent (set op for 'Selected documents'),
you usually use the following:
Set collection = db.UnprocessedDocuments
I skip the obvious initial Dim's and Set's, as we all know them.
This works fine most of the time. I must say however that the 'name' of this property does not sound obvious for a newbie.
However, I had an issue today (yes, I know it's Saturday, but we, independent professionals, need to make a living every day of the week ;-),
when I called an agent from an action button on an embedded view.
The db.UnprocessedDocuments referred to the 'parent' document, not to the selected documents in the view. Very annoying.
Then I remembered a NotesUIView property 'Documents':
Set uiview = Workspace.CurrentView
Set collection = uiview.Documents
Set collection = uiview.Documents
This time the collection was correctly filled
(from a regular view, as well as from an embedded view).
I hardly ever use this property, and I don't know why,
as it is very convenient (and aptly named).
Any SWOT (Strengths, Weaknesses, Opportunities, or Threats) using this solution ?
Updated: Thanks to Jens who commented that when there's no checkmark in front of the selected documents, uiview.documents return an empty collection. This can be solved by addding the following:
If collection.Count=0 Then
Set doc = db.GetDocumentByID(uiview.CaretNoteID) 'another valuable hardly known property
If Not (doc Is Nothing) Then Call collection.AddDocument(doc)
End If
Set doc = db.GetDocumentByID(uiview.CaretNoteID) 'another valuable hardly known property
If Not (doc Is Nothing) Then Call collection.AddDocument(doc)
End If
Category: Domino Notes Show-n-Tell Thursday SnTT | Technorati: Domino, Notes, Show-n-Tell Thursday, SnTT
Comments (5)
If only one document is selected in the view and no checkmark is set for that document, db.UnprocessedDocuments contains this one document while uiview.Documents does not. If a checkmark is set, both collections contain the document.
If more than one document is selected, both will contain the same number of documents.
I don't know how it behaves in Java views, though.
Hi,
I used unprocessedDocument method to get selected(marked) documents in view. But in documentcollection it only shows 1 document. Below is the code I used.
Dim Session As NotesSession
Dim CurrentDb As NotesDatabase
Dim CurrentDocColl As NotesDocumentCollection
Dim CurrentDoc As NotesDocument
Set Session = New NotesSession
Set CurrentDb = Session.Currentdatabase
Set CurrentDocColl = CurrentDb.Unprocesseddocuments 'This code is to get the handle of all selected documents.
Set CurrentDoc = CurrentDocColl.Getfirstdocument
While Not CurrentDoc Is Nothing
CurrentDoc.dt_LaunchedtoMAS = Cdat(Inputbox$("Please Enter Date to Change:"))
Call CurrentDoc.Save(True, False)
Set CurrentDoc=CurrentDocColl.Getnextdocument(Currentdoc)
Wend
@Nida,
Your code seems correct to me.
Check your agent settings. It is important to have the agent run on 'selected documents'.
Otherwise unprocesseddocuments does not return the correct collection.
Thanks it worked. :)
Thanks, you saved my day