This entry was posted on Friday, December 14th, 2007 at 3:55 pm and is filed under IBM Lotus Notes, LotusScript. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
BizzyBee’s BizzyThoughts
Think Outside The Hive - About Notes and Web
Find and use a doclink in a richtext field
Challenge
- Find doclink in a richtext field.

- Use doclink to get linked document and retrieve some values from it.
The code
Not that hard to understand…
Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim dc As NotesDocumentCollection
Dim doc As NotesDocument
Dim linkdoc As NotesDocument
Dim rtitem As NotesRichTextItem
Dim rtnav As NotesRichTextNavigator
Dim rtrange As NotesRichTextRange
Dim rtlink As NotesRichTextDoclink
Set db = session.CurrentDatabase
Set dc = db.UnprocessedDocuments
If dc.Count = 0 Then
Messagebox "No document selected",, "No doc"
Exit Sub
End If
Set doc = dc.GetFirstDocument
While Not(doc Is Nothing)
'First find your richtext item
Set rtitem = doc.GetFirstItem("Body") 'Change this to your rtfield
If Not(rtitem Is Nothing) Then
Set rtnav = rtitem.CreateNavigator
'Use the first doclink
If rtnav.FindFirstElement(RTELEM_TYPE_DOCLINK) Then
Set rtrange = rtitem.CreateRange
Call rtrange.SetBegin(rtnav)
Set rtlink = rtnav.GetElement
Dim linkdb As New NotesDatabase("", "")
'Investigate the link to find the linked document
If linkdb.OpenByReplicaID (rtlink.ServerHint, rtlink.DBReplicaID) Then
Set linkdoc = linkdb.GetDocumentByUNID (rtlink.DocUNID)
If Not(linkdoc Is Nothing) Then
'Here comes the code where you do things with the related doc
End If
End If
End If
End If
Set doc=dc.GetNextDocument(doc)
Wend
End Sub
Articles
Da Honey Pot
About me

December 20th, 2007 at 4:08 pm
It would be interesting to add the current document as a doclink in the linked (target) document, so you could create cross connections.
of course you should check if such a document link isn’t already available on the document.
question how would you create a doclink from source into a target in a specific field in an automated process ?
December 20th, 2007 at 4:11 pm
would be intressting so see if you would create cross connections from each doclink in the source into the target document(s)
how would you create such a linking in an automated process (agent) ?
December 21st, 2007 at 10:28 am
If I understand your question right I think this isn’t that hard (and I’m quite sure I coded this in the past) using AppendDocLink in LotusScript. Is that what you meant?