Adding Doclink To Uidoc, After The Fact

We had an application that contained portfolio information. Quite often, two
or more portfolios would merge. When this occured, we created a Merge
document. This was a response to the portfolio that was no longer valid, and
contained a doclink to that original document. This merge document, also
required a doclink to the portfolio that remained. Since you cannot insert a
doclink into a uidoc, this was done with the following script in Postopen - so,
the next time the merge document was opened, the doclink would be available.
Sub Postopen(Source As Notesuidocument)
Dim workspace As New NotesUIWorkspace
Dim session As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim view As NotesView
Dim portDoc As NotesDocument ' remaining portfolio doc
Dim rtitem As NotesRichTextItem ' RT field on merge form
Dim portID As String ' Portfolio ID of
remaining portfolio

Set db = session.CurrentDatabase
Set Source = workspace.CurrentDocument
Set doc = Source.Document
Set view = db.GetView("(ProfilePortfolios)") ' view containing all
portfolio docs

portID = doc.NewPortfolioShortName(0)
Set portDoc = view.GetDocumentByKey(portID, True)
Set rtitem = doc.GetFirstItem( "NewProfileDoc" )

If Source.IsNewDoc Then ' if it's a new document,
then skip
Exit Sub
Elseif Not rtitem.Contains(" - ") Then ' check for leading dash
Call rtitem.AppendText(" - ") ' add leading dash
Call rtitem.AppendDocLink( portDoc, "Link to New Portfolio Profile"
) ' add doclink
Call doc.Save(True, False) ' save current doc
Call Source.Close ' close current doc
Call workspace.EditDocument(False, doc) ' reopen current doc in
editmode
Call doc.Save(True,False) ' resave current doc
End If

End Sub

This was first published in November 2000

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.