I’m using an agent to process new and modified documents. If the document contains an item called “ReplacementUnid” then I want to change doclinks from pointing at the current document to pointing to the document referred to by that item.
The code runs ok (I’ve checked in debug mode) BUT it doesn’t seem to have any effect. The doclinks and anchor links still stubbornly points to the wrong document as if the code hadn’t run at all.
Am I missing something? Do I need to do something apart from saving the document? I’m beginning to think that NotesRichTextNavigator is read-only.
Or maybe I’m missing something really obvious… (wouldn’t be the first time!)
A free beer (or 3, or 4) awaits anyone who can help (you pay the air-fare to London though ![]()
Here’s the code if anyone is interested…
Sub UpdateAnchorLinks(doc As NotesDocument)
Dim body As NotesRichTextItem
Dim rtnav As NotesRichTextNavigator
Dim rtlink As NotesRichTextDocLink
Dim sThisDbReplicaId As String
Dim sThisDocId As String
If (doc.HasItem("ReplacementUnid")) Then
Set body = doc.GetFirstItem("DocBody")
Set rtnav = body.CreateNavigator
' Get this database's replica id
sThisDbReplicaId = doc.ParentDatabase.ReplicaID
' Get this document's doc id
sThisDocId = doc.UniversalID
If rtnav.FindFirstElement( RTELEM_TYPE_DOCLINK ) Then
Do
Set rtlink = rtnav.GetElement
' Only change the link if the replica id is for this db and the doc id is for this document
If ((rtlink.DBReplicaID = sThisDbReplicaId) And (rtlink.DocUnID = sThisDocId)) Then
rtlink.DocUNID = doc.ReplacementUnid(0) ' This line actually runs but doesn't change the (anchor) doclink !!!!
End If
Loop While rtnav.FindNextElement
End If
doc.RemoveItem("ReplacementUnid")
Call doc.Save(True, True)
End If
End Sub