Hi all,I come to a scenario that on a view, the user can select the document(s) by clicking with a check mark, then press a button to perform some action on these selected documents.
I use following codes :
Dim Session As New NotesSession
Dim DB As NotesDatabase
Dim Collection As NotesDocumentCollection
Dim Doc As NotesDocument
Set DB = Session.CurrentDatabase
Set Collection = DB.UnprocessedDocuments
If Collection.Count > 0 Then
Set Doc = Collection.GetFirstDocument
While Not Doc Is Nothing
'do something with the document
Messagebox "Document Subject = " & Doc.Subject(0)
Set Doc = Collection.GetNextDocument(Doc)
Wend
Else
Messagebox “No selected Documents”
End If
The code works if user does select one or more documents. However, if the user doesn’t select any document (ie. no document with check mark now), but since the cursor will always stand on one document, this record will fall on the UnprocessedDocuments Collection. So I never the “No selected Documents” message never come out even though no document is selected.
Hope you understand my poor English, any idea?
Thanks in advance!
Subject: ? Problem on db.UnprocessedDocuments property
Harry, Notes considers that if a document in a view is highlighted, then it is selected, and db.UnprocessedDocuments will include it in the collection. If you were in a view that was categorized, and the highlight was on a category rather than a document, then Collection.Count would = 0, and your Else would work.
Now, if the user did select one or more documents in the view by checkmarking them, and they had a document highlighted that did not have a checkmark by it, then that document would not be included in the .UnprocessedDocuments collection; only those docs with the checkmarks would.
HTH
Subject: RE: ? Problem on db.UnprocessedDocuments property
Really thanks for your prompt reply.
Is there any method that I can check out the document is really selected (have a checkmark on it) but not highlighted?
Thanks again.
Subject: RE: ? Problem on db.UnprocessedDocuments property
Use the notesuiview.documents method. That will only get documents that are actually selected with a checkmark.
Dan
Subject: RE: ? Problem on db.UnprocessedDocuments property
BTW: If you have the agent target set as “All selected documents” it will never reach the, Messagebox “No selected Documents” bit of your code if no documents are selected/highlighted - ie. If the highlighted line is a catagory and no documents selected. The agent will just not run.
One possible solution to your problem is to use the notesUIWorkspace class to identify, which document is currently highlighted in the view…so from your code:
Dim Session As New NotesSession
Dim workspace As New NotesUIWorkspace
Dim DB As NotesDatabase
Dim Collection As NotesDocumentCollection
Dim Doc As NotesDocument
Dim caretID As String
Set DB = Session.CurrentDatabase
caretID = workspace.CurrentView.CaretNoteID
Set Collection = DB.UnprocessedDocuments
If Collection.Count > 0 Then
Set Doc = Collection.GetFirstDocument
If collection.count = 1 And Doc.NoteID = caretID Then
Messagebox "No selected Documents"
Else
While Not Doc Is Nothing
'do something with the document
Messagebox "Document Subject = " & Doc.Subject(0)
Set Doc = Collection.GetNextDocument(Doc)
Wend
End If
Else
Messagebox "No selected Documents"
End If
The agent should return “No selected documents” if there is one unprocessed document and it is currently highlighted in the view. The only problem with this approach is when the user selects one document and also highlights it in the view - I’ve not managed to find a solution to that, someone else might be able to suggest a way round this?
Subject: RE: ? Problem on db.UnprocessedDocuments property
Harry, I might not have been too clear in my response.
If a doc is highlighted, and no docs are checkmarked, then there will be one doc in the collection. The one that is highlighted.
Now, say you have three docs checkmarked, and another doc highlighted. The highlighted doc will not be considered part of the collection. There will only be three docs in that collection; the ones that are checkmarked.
Subject: You can’t use UnprocessedDocs in button in view
You can’t directly use the UnprocessedDocuments method in a button in a view because it doesn’t give you the results you expect.
Instead what you need to do is put some code in the button to call an agent. The agent should be set to run on selected documents and you can put all your code in there. This will work as you expect it to.
Alex
Subject: RE: You can’t use UnprocessedDocs in button in view
Hmm, seems to have always worked for me in an action button. Try this code in an action on a view. Will report the number of docs you have highlighted or selected, or will report 0 if you have a category highlighted.
Dim s As New NotesSession
Dim db As NotesDatabase
Dim coll As NotesDocumentCollection
Dim doc As NotesDocument
Set db = s.CurrentDatabase
Set coll = db.UnprocessedDocuments
Msgbox coll.Count
Subject: Ok I should clarify…
There are certain conditions under which the UnprocessedDocuments property of a view action button doesn’t always return the required results.
So if you don’t get it to work as expected try calling an agent which acts on the selected documents.
Subject: Agent does the same…
Wow, just so glad to come back and see you guys’ help.Actually Jerry and Stephen points out very clear, the problem is unprocesseddocuments also include the highlighted doc.
I have tried putting the codes to an agent (set to run on selected docs) and in fact the result is the same. If there is no checkmark for any doc, the highlighted one will still be collected as unrocesseddocuments. I just can’t achieve what Alex had suggested.
Anyway, so much thanks guys.