例: DocUNID property (NotesRichTextDocLink - LotusScript)

  1. 次のエージェントは、現在の文書の Body アイテム内にある最初の (または唯一の) 文書リンクの参照先文書での Subject アイテムの値を表示します。

    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. 次のエージェントは、リンクを含む文書内の最初の文書リンクを取得し、参照先データベース内での次の文書をポインタによって示すように変更します。エラー検査コードについては、例 1 を参照してください。
    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