DocLink remove

Problem:2 documents (say DocA, DocB) each one has a richtextitem where a doclink to other document is placed. The 2 documents editing is based on different form (i.e. DocA.Form<>DocB.Form).

The user must be able to remove such references from both documents acting from one of them, in order to save consistency…

(i.e. open DocA, click on a operation and remove the doclink from DocA and DocB).

Solution that doesn’t work:

I created an operation on both the form and associate this script:

Sub Click(Source As Button)

Dim protocollo As String



' ask for prot. number of the doclink to be removed

protocollo = Inputbox("Protocollo:")

If protocollo="" Then 

	Messagebox "Invalid prot. number..."

	Exit Sub

End If



Dim docB As notesdocument

' check for valid document associated to doclink

Set docB = GetDocument(CurrentDoc.ParentDatabase, protocollo,"(ViewByProt)")



' check the result

If docB  Is Nothing Then

	Messagebox "Invalid document..."	

Else

          '  CurrentUIDoc and CurrentDoc are global reference

          ' instanciated in form PostOpen event....

	CurrentUIDoc.EditMode=True

	Call CurrentUIDoc.Save

	CurrentUIDoc.EditMode=False

	

	Call RemoveDocLink(CurrentDoc, docB.UniversalID, True)

	Call RemoveDocLink(docB, CurrentDoc.UniversalID, True)

	

	Messagebox "Reference removed..."



            ' reload the current doc in order to show the modifies

            ' in Richtextitem

	CurrentUIDoc.Close(True)

	Set CurrentUIDoc = CurrentSpace.EditDocument(False,CurrentDoc,,,,True)

	

End If

End Sub

The RemoveDocLink is a function in a sharedscript of utilities as follows:

Sub RimuoviDocLink(doc As NotesDocument, uid As String, aggLista As Boolean)

Dim rti As NotesRichTextItem

Dim dl As NotesRichTextDoclink



Set rti=RitornaRTI(doc,"TestiCorrelati")

Set dl=RitornaDocLink(rti,uid,2)



If Not (dl Is Nothing) Then	

	

	dl.Remove

	

	' if requested, update the field with a list of doclink hotspots

	If aggLista Then

		doc.ListaRif=RitornaListaDocLink(rti,", ")

	End If

	

	' save document

	doc.Save False, False	

	

End If

End Sub

Function RitornaDocLink(rti As NotesRichTextItem ,hotspot As String, mode As Integer) As NotesRichTextDoclink

' multi purpous function: returns (if exists) the doclink regarding the selected property value 



Dim rtnav As NotesRichTextNavigator

Dim dl As NotesRichTextDoclink



Set rtnav = rti.CreateNavigator



Set dl = rtnav.GetFirstElement(RTELEM_TYPE_DOCLINK)	



Do  While Not(dl Is Nothing)

	' search criteria

	Select Case mode

	Case 1

		If dl.HotSpotText = hotspot Then Exit Do

	Case 2

		If dl.DocUnID = hotspot Then Exit Do

	Case 3

		If dl.ViewUnID = hotspot Then Exit Do

	Case 4

		If dl.DBReplicaID = hotspot Then Exit Do

	End Select

	Set dl = rtnav.GetNextElement(RTELEM_TYPE_DOCLINK)	

Loop



Set	RitornaDocLink= dl

End Function

Function RitornaRTI(doc As notesdocument, nomeCampo As String) As NotesRichTextItem

Dim rti As NotesRichTextItem

Dim ni As NotesItem



Set ni = doc.GetFirstItem(nomeCampo)

If ni Is Nothing Then

	' if not available, the richtext is created

	Set rti= doc.CreateRichTextItem(nomeCampo)

Else

	' if available, but not richtext type, it is dropped and recreated as richtext

	If ni.type<>1 Then

		doc.RemoveItem(nomeCampo)

		Set rti= doc.CreateRichTextItem(nomeCampo)

	Else

	' if available and richtext, then it is returned

		Set rti = doc.GetFirstItem(nomeCampo)	

	End If

End If



Set RitornaRTI=rti

End Function

Unfortunately, during the second call to RemoveDocLink I receive an “Edit Rich text failed” error on dl.remove…

Any hints?

TIA

Giuseppe