• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 600
  • Last Modified:

Accessing a NotesUIView outside of its events

I need to access the currently selected documents in a view & process them from script via an action button, similar to the way a user can select multiple documents then click Print or Delete.

I know the NotesUIView class contains a Documents property that represents: "All the documents that the current NotesUIView event is working on." This seems to be what I'm after. But the only way to access the NotesUIView class is when it is passed to you via the view events. My button would operate outside of those events. How can I get at the currently selected documents collection? Could I cause one of those events to fire & then handle the NotesUIView.Documents collection? If so, which event is best & how would I trigger it?
  • 3
1 Solution
RayboneAuthor Commented:
Edited text of question.
Create an agent that will run the action you desire with LotusScript.  With that action, use:

Dim session as New NotesSession
Dim db as NotesDatabase
Dim collection as NotesDocumentCollection

Set db = session.CurrentDatabase
Set collection= db.UnprocessedDocuments
'this will grab all selected documents in the view if your agent is selected to run on selected documents
'next process all the documents anyway you wish

If I had to give you steps...
1) Create an agent for the action you desire
2) Create an action button in the view for the corepsonding action
3) call that action w/ @Command([ToolsRunMacro]; agentName) in the action button

--Good luck; I hope this answered your question
RayboneAuthor Commented:
Thanks for the help. I just figured out a really ugly way to do what I needed:

I created a Shared Folder & Called it Printer. Next I wrote my code to the queryaddtofolder event of the view. The code tests for the Printer folder & if met, processes the docs then sets Continue to False so they don't copy.

I'm going to try your way. It looks a lot cleaner.
RayboneAuthor Commented:
Your solution was exactly the way to go!!! Not only was it cleaner, but it allowed me to keep the code I needed to extract & print the attachments in 1 place, then call it via Action Buttons from several views & the form itself. The code always works for the selected document(s), no matter where it's being called from.


Just in case anyone's interested, here's the final Print Agent code:

Sub Initialize
     On Error Goto ErrorHandler
     Dim session As New NotesSession
     Dim db As NotesDatabase
     Dim dc As NotesDocumentCollection
     Dim rtitem As Variant
     Dim FileName As String
     Set db = session.CurrentDatabase  ' Get the Selected Doc Collection
     Set dc= db.UnprocessedDocuments
     If dc.count > 0 Then ' if there are Selected Documents, print them
          Set Application = CreateObject("Word.application.8") ' Instantiate Word        
          For j =  1 To dc.Count
               Set doc = dc.GetNthDocument(j)
               Set rtitem = Doc.GetFirstItem( "FileToAppend" ) ' Get the File Attachment
               If ( rtitem.Type = RICHTEXT ) Then
                    Forall o In rtitem.EmbeddedObjects
                         If o.Type = EMBED_ATTACHMENT  Then
                              filename = "C:\Windows\Temp\" + Format(Now,"yyyymmddhhnns")+ o.Name
                              Call o.ExtractFile ( filename ) ' Extract it to a file for printing
                         End If
                    End Forall
                    Call Application.Documents.Open(FileName)
                    Set myDoc = Application.Documents(1)
                    myDoc.PrintOut (False) ' The false option is for Background & tells Word to wait until action is done to continue code. Prevents the
                                                    ' Next few lines from killing word before it's done printing.
               End If              
          Set MyDoc = Nothing
          Set Application = Nothing
          Continue = False  
     End If
     Exit Sub
     Exit Sub
     Messagebox "Error" & Str(Err) & ": " & Error$
     Resume Next

End Sub

Thanks Again,
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now