Examples: DocUNID property (NotesRichTextDocLink - LotusScript)

  1. This agent displays the value of the Subject item of the target document of the first or only doclink in the Body item of the current document.

    Dim session As NotesSession
    Dim db As NotesDatabase
    Dim dc As NotesDocumentCollection
    Dim doc As NotesDocument
    Dim rti As NotesRichTextItem
    Dim rtnav As NotesRichTextNavigator
    Dim rtlink As NotesRichTextDocLink
    Sub Initialize
      Set session = New NotesSession
      Set db = session.CurrentDatabase
      Set dc = db.UnprocessedDocuments
      Set doc = dc.GetFirstDocument
      Set rti = doc.GetFirstItem("Body")
      Set rtnav = rti.CreateNavigator
      If Not rtnav.FindFirstElement(RTELEM_TYPE_DOCLINK) Then
        Messagebox "No doclinks in Body item",, "No doclinks"
        Exit Sub
      End If
      Set rtlink = rtnav.GetElement
      If rtlink.DocUNID = String$(32, "0") Then
        Messagebox "Link does not have a doc component",, _
        "No doc"
        Exit Sub
      End If
      Dim linkDb As New NotesDatabase("", "")
      If Not linkDb.OpenByReplicaID("", _
      rtlink.DbReplicaID) Then
        Messagebox "No local replica",, "Cannot find database"
        Exit Sub
      End If
      Dim linkDoc As NotesDocument
      On Error Goto InvalidUNID
      Set linkDoc = linkDb.GetDocumentByUNID(rtlink.DocUNID)
      Messagebox linkDoc.Subject(0),, "Subject of document"
      Exit Sub
    InvalidUNID:
      Messagebox "Cannot locate document",, "No document"
      Exit Sub
    End Sub
  2. This agent gets the first doclink element in the document containing the link and changes it to point to the next document in the target database. Refer to example 1 for error checking code.
    Dim session As NotesSession
    Dim db As NotesDatabase
    Dim dc As NotesDocumentCollection
    Dim doc As NotesDocument
    Dim rti As NotesRichTextItem
    Dim rtnav As NotesRichTextNavigator
    Dim rtlink As NotesRichTextDocLink
    Sub Initialize
      Dim linkDb As New NotesDatabase ("", "")
      Dim linkDc As NotesDocumentCollection
      Dim linkDoc As NotesDocument
      Dim oldLink As String ' subject of current linked document
      
      ' Open the document containing the link
      Set session = New NotesSession
      Set db = session.CurrentDatabase
      Set dc = db.UnprocessedDocuments
      Set doc = dc.GetFirstDocument
      
      ' Get the doclink
      Set rti = doc.GetFirstItem("Body")
      Set rtnav = rti.CreateNavigator
      If Not rtnav.FindFirstElement(RTELEM_TYPE_DOCLINK) Then
        Messagebox "No doclinks in Body item",, "No doclinks"
        Exit Sub
      End If
      Set rtlink = rtnav.GetElement
      If rtlink.DocUNID = String$(32, "0") Then
        Messagebox "Link does not have a doc component",, _
        "No doc"
        Exit Sub
      End If
      
      ' Open the document in the target database
      If Not linkDb.OpenByReplicaID("", _
      rtlink.DbReplicaID) Then
        Messagebox "No local replica",, "Cannot find database"
        Exit Sub
      End If
      On Error Goto InvalidUNID
      Set linkDoc = linkDb.GetDocumentByUNID (rtlink.DocUNID)
      oldLink = linkDoc.Subject(0)
      
      ' Get the next document in the target database
      Set linkDc = linkDb.AllDocuments
      Set linkDoc = linkDc.GetDocument (linkDoc)
      Set linkDoc = linkDc.GetNextDocument (linkDoc)
      
      ' Change the link
      Messagebox "Changing document link from " & oldLink & _
      " to " & linkDoc.Subject(0)
      rtlink.DocUNID = linkDoc.UniversalID
      Call doc.Save (True, True)
      Exit Sub
    InvalidUNID:
      Messagebox "Cannot locate document",, "No document"
      Exit Sub
    End Sub