How to access a Notes doclink in a newly created Link Message via LotusScript?

The following custom function is to be called from PostOpen of the Link Message form in the R6 mail template to automatically append a http URL to the document represented by the Notes DocLink.

The code works so far, however it seems I must do a uidoc.save to later get a valid rtitem in the backend doc. This can cause unwanted Drafts in case the user later on cancels the sending of the link message.

How can I do the same WITHOUT badly calling source.save in PostOpen?

Any help is appreciated.

Dietmar

Function AppendDocURL (source As NotesUiDocument) As Integer

'Create URLString



If Not source.IsNewDoc Then

	Exit Function

End If



Dim doc As NotesDocument

Dim rtitem As NotesRichTextItem

Dim rtnav As NotesRichTextNavigator

Dim rtlink As NotesRichTextDoclink

Dim dburl As String 



Set doc =source.Document

Call source.Save 'very bad style but seems to be required to get a valid doc.rtitem?

Set rtitem = doc.GetFirstItem("Body")

Set rtnav = rtitem.CreateNavigator



If Not rtnav.FindFirstElement(RTELEM_TYPE_DOCLINK) Then

	Print "No doclink in Body item",, "No doclinks"

	Exit Function

End If

Set rtlink = rtnav.GetElement

Dim linkDb As New NotesDatabase("", "")

If linkDb.OpenByReplicaID(rtlink.ServerHint, rtlink.DbReplicaID) Then

	'Sorry folks, another quick&dirty style, I better should fetch the full hostname from the linkdb.server document:

	dburl = "http://" & Strleft(linkdb.Server,"/") & ".acme.com/" & rtlink.DBReplicaID & "/$All/"& rtlink.DocUnID & "?OpenDocument"

	If rtlink.ServerHint = "" Then 'this is a local db, we cannot refer to it via http URL

		Exit Function

	End If

	Print dburl

	'Append the URL to the Body field

	Call source.FieldAppendText("Body", "  " & dburl)		

End If

End Function

Subject: How to access a Notes doclink in a newly created Link Message via LotusScript?

why not add code in the queryclose event of the document, that self deletes itselfe if cancelled?

Subject: RE: How to access a Notes doclink in a newly created Link Message via LotusScript?

I suppose this to be considered as a workaround. However, I’d better like to avoid workarounds if possible. Is there no way to access a rtitem object of a newly created document?