Getting the current document from a button in an embedded editor

Consider the following scenario:
a lotus form containing an embedded view and an embedded editor, the 2 embedded controls are linked together according to targeting by linking an embedded editor to an embedded view.
The embedded editor contains a button that tries to get the current document (often called uidoc) with the code:

Sub Click(Source As Button)

Dim w As New NotesUIWorkspace
Dim uidoc As NotesUIDocument

Set uidoc = w.CurrentDocument

End Sub

but this code returns the NotesUIDocument of the document linked to the embedded editor and not the NotesUIDocument linked to the main document.
To get the current document you have to:

  1. declare a global variable in the form of the embedded editor under (Globals) -> (Declarations)
    Dim uidoc As NotesUIDocument
    
  2. modify the event (Globals) -> Initialize where you initialize uidoc
    Sub Initialize
    
    Dim w As New NotesUIWorkspace
    
    Set uidoc = w.CurrentDocument
    
    End Sub
    

Now the variable uidoc points to the current document and being a global variable you can use in the Click event of the button and in other parts of the embedded editor.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.