Examples: ViewUNID property

  1. This agent displays the name of the target view 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.ViewUNID = String$(32, "0") Then
        Messagebox "Link does not have a view component",, _
        "No view"
        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 linkView As NotesView
      foundIt = False
      Forall view In linkDb.Views
        If view.UniversalID = rtlink.ViewUNID Then
          foundIt = True
          Set linkView = view
          Exit Forall
        End If
      End Forall
      If foundIt Then
        Messagebox linkView.Name,, "View name"
      Else
        Messagebox "Cannot locate view",, "No such view"
      End If
    End Sub
  2. This agent finds the target view of the doclink, gets the next view in the database, and changes the doclink to point to the first document in that view.
    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 linkView As NotesView
      Dim linkDc As NotesDocumentCollection
      Dim linkDoc As NotesDocument
      Dim foundView As Boolean
      Dim msg1 As String, msg2 As String
      
      ' 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.ViewUNID = String$(32, "0") Then
        Messagebox "Link does not have a view component",, _
        "No view"
        Exit Sub
      End If
     
      ' Find the view in the target database; get the handle to 
      ' the next view in the database
      If Not linkDb.OpenByReplicaID("", _
        rtlink.DbReplicaID) Then
        Messagebox "No local replica",, "Cannot find database"
        Exit Sub
      End If
      foundView = False
      Forall v In linkDb.Views
        If foundView Then
          ' get the next view
          Set linkView = v
          Exit Forall
        End If
        If v.UniversalID = rtlink.ViewUNID Then
          Set linkView = v
          msg1 = linkView.Name
          foundView = True
        End If
      End Forall
      
      ' Get the first document in the new view
      On Error Goto InvalidUNID
      Set linkDoc = linkView.GetFirstDocument
      
      ' change link
      rtlink.ViewUNID = linkView.UniversalID
      rtlink.DocUNID = linkDoc.UniversalID
      msg2 = linkDoc.Topic(0) & " in view: " & linkView.Name
      Messagebox "from document in view: " & _
      msg1 & Chr(13) & "to " & msg2, , _
      "Changing doclink"
      Call doc.Save (True, True)
      Exit Sub
    InvalidUNID:
      Messagebox "Cannot locate document",, "No document"
      Exit Sub
    End Sub