Examples: EditDocument method

  1. This view action script opens the document that's currently highlighted in the view in Edit mode.
    Sub Click(Source As Button)
      workspace As New NotesUIWorkspace
      Call workspace.EditDocument( True )
    End Sub
  2. This view action script opens the document that's currently highlighted in the view in Edit mode, and moves the insertion point to the Body field.
    Sub Click(Source As Button)
      Dim workspace As New NotesUIWorkspace
      Dim uidoc As NotesUIDocument
      Set uidoc = workspace.EditDocument( True )
      Call uidoc.GotoField( "Body" )
    End Sub
  3. This agent opens a specified document in Read mode. The document is selected through GetDocumentByKey from a view sorted on the CustomerNumber field.
    Sub Initialize
      Dim ws As New NotesUIWorkspace
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim view As NotesView
      Dim doc As NotesDocument
      Dim customerNumber As String
      Set db = session.CurrentDatabase
      Set view = db.GetView("All Documents by CustomerNumber")
      customerNumber = Inputbox$("Customer number")
      If customerNumber <> "" Then
        Set doc = view.GetDocumentByKey(customerNumber, True)
        If doc Is Nothing Then
          Messagebox "Customer # " & customerNumber,, _
          "Customer not found"
        Else
          Call ws.EditDocument(False, doc)
        End If
      End If
    End Sub
  4. This agent opens a specified document in Read mode to the anchor link whose text is "Address," and prevents the user from switching to Write mode. The document is selected through GetDocumentByKey from a view sorted on the CustomerNumber field.
    Sub Initialize
      Dim ws As New NotesUIWorkspace
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim view As NotesView
      Dim doc As NotesDocument
      Dim customerNumber As String
      Set db = session.CurrentDatabase
      Set view = db.GetView("All Documents by CustomerNumber")
      customerNumber = Inputbox$("Customer number")
      If customerNumber <> "" Then
        Set doc = view.GetDocumentByKey(customerNumber, True)
        If doc Is Nothing Then
          Messagebox "Customer # " & customerNumber,, _
          "Customer not found"
        Else
          Call ws.EditDocument(False, doc, True, "Address")
        End If
      End If
    End Sub
  5. This agent suppresses returning the NotesUIDocument object because it executes in the frame in which it is opening the document. Otherwise, the error lsERR_LSXU13_ANCESTOR_TARGET_FRAME would be raised. The document opens but the returned NotesUIDocument object is Nothing. See also the next example.
    Sub Initialize
      Dim ws As New NotesUIWorkspace
      Dim uidoc As NotesUIDocument
      Dim s As New NotesSession
      Dim db As NotesDatabase
      Dim view As NotesView
      Dim doc As NotesDocument
      Set db = s.CurrentDatabase
      Set view = db.GetView("All Documents")
      Set doc = view.GetFirstDocument
      Call ws.OpenFrameSet("main")
      Call ws.SetTargetFrame("left")
      Set uidoc = ws.EditDocument(False, doc, False,,False)
    End Sub
  6. This agent does not suppress returning the NotesUIDocument object but traps the error lsERR_LSXU13_ANCESTOR_TARGET_FRAME. In this case, the document does not open.
    %INCLUDE "lsxuierr.lss"
    Sub Initialize
      On Error Goto handleError
      Dim ws As New NotesUIWorkspace
      Dim uidoc As NotesUIDocument
      Dim s As New NotesSession
      Dim db As NotesDatabase
      Dim v As NotesView
      Dim doc As NotesDocument
      Set db = s.CurrentDatabase
      Set view = db.GetView("All Documents")
      Set doc = view.GetFirstDocument
      Call ws.OpenFrameSet("main")
      Call ws.SetTargetFrame("left")
      Set uidoc = ws.EditDocument(False, doc, False)
      Exit Sub
    handleError:
      If Err() = lsERR_LSXUI3_ANCESTOR_TARGET_FRAME Then
        Exit Sub
      Else
        Messagebox Err(),, Error()
        Exit Sub
      End If
    End Sub
  7. This action is on a form for response documents. It edits the parent document using the existing UI instance if any.
    Sub Click(Source As Button)
      REM Create workspace, UI objects, and back-end objects
      Dim ws As New NotesUIWorkspace
      Dim uidb As NotesUIDatabase
      Dim uidoc As NotesUIDocument
      Dim db As NotesDatabase
      Dim doc As NotesDocument
      Dim parentDoc As NotesDocument
      Set uidb = ws.CurrentDatabase
      Set uidoc = ws.CurrentDocument
      Set db = uidb.Database
      Set doc = uidoc.Document
      REM Save if new so there will be a UNID
      If uidoc.IsNewDoc Then Call uidoc.Save
      REM Get the parent document
      Dim unid As String
      unid = doc.ParentDocumentUNID
      If unid = "" Then Exit Sub ' Just in case
      Set parentDoc = db.GetDocumentByUNID(unid)
      REM Open parent document
      REM Do not open a new window if document is already in the UI
      Call ws.EditDocument(True, parentDoc,,,, False)
    End Sub