Examples: GetDocumentByUNID method

  1. This agent gets the parents of all the response documents in the current database.
    Sub Initialize
      Dim s As New NotesSession
      Dim db As NotesDatabase
      Dim dc As NotesDocumentCollection
      Dim doc As NotesDocument, pdoc As NotesDocument
      Dim docSubj As String, pdocSubj As String
      Set db = s.CurrentDatabase
      Set dc = db.AllDocuments
      Set doc = dc.GetFirstDocument
      While Not(doc Is Nothing)
        If doc.IsResponse Then
          Set pdoc = _
          db.GetDocumentByUNID(doc.ParentDocumentUNID)
          docSubj = doc.Subject(0)
          pdocSubj = pdoc.Subject(0)
          Messagebox "Parent: " + pdocSubj,, docSubj
        End If
        Set doc = dc.GetNextDocument(doc)
      Wend
    End Sub
  2. This agent demonstrates handling lsERR_NOTES_BAD_UNID. The UNID is deliberately altered to cause the error.
    %INCLUDE "lsxbeerr.lss"
    Sub Initialize
      On Error lsERR_NOTES_BAD_UNID Goto processError
      Dim s As New NotesSession
      Dim db As NotesDatabase
      Dim dc As NotesDocumentCollection
      Dim doc As NotesDocument, pdoc As NotesDocument
      Dim docSubj As String, pdocSubj As String
      Dim badID As String
      Set db = s.CurrentDatabase
      Set dc = db.AllDocuments
      Set doc = dc.GetFirstDocument
      While Not(doc Is Nothing)
        If doc.IsResponse Then
          docSubj = doc.Subject(0)
          ' Deliberately munge UNID
          badID = "Z" & Right(doc.ParentDocumentUNID, 31)
          Set pdoc = db.GetDocumentByUNID(badID)
          pdocSubj = pdoc.Subject(0)
          Messagebox "Parent: " + pdocSubj,, docSubj
        End If
    getNextDocument:
        Set doc = dc.GetNextDocument(doc)
      Wend
      Exit Sub
    processError:
      Messagebox docSubj,, "Bad UNID for ..."
      Resume getNextDocument
    End Sub