Appenddoclink doesn't work in script library

Hi,

Can somebody help me?

I have created a LN script (“CreateLink”) for document linking in a script library. I call this sub (“CreateLink”) from document’s queryclose event. It works right under R5.

We tested it under R6.0.3 and there is a strange error.

The sript runs (I can see in debugger) but the link there isn’t in the document after the runnig.

If I copy the code of the “CreateLink” sub to the document’s queryclose event it works correctly.

Here is the code:

Sub CreateLink(srcdb As Notesdatabase, viewnm As String, key As Variant, currdoc As Notesdocument, richfield As String)

Dim ws As New Notesuiworkspace	

Dim session As New Notessession	

Dim view As Notesview

Dim srcdoc As Notesdocument

Dim richtext As Notesrichtextitem



Set view = srcdb.Getview(viewnm)

i = 0



'Richtext field setting

Set richtext = currdoc.Getfirstitem(richfield)

'Delete earlier links

Set item = currdoc.Replaceitemvalue(richfield, "" )



'Creating links

Forall txt In key

	'Document searching

	Set srcdoc = view.Getdocumentbykey(txt)

	'Create link to document

	If Not srcdoc Is Nothing Then

		Call richtext.Appenddoclink(srcdoc, "") 'this method do nothing if I call it from queryclose event.

	Else

		Call richtext.Appendtext(" - ")

	End If

	

	If Ubound(key) > 0 And i < Ubound(key) Then

		Call richtext.Addnewline(1)

	End If

	i = i + 1

End Forall

End Sub

Have you any idea what is problem?

Thank you in advance,

Best Regards

T. Krivan

Subject: Appenddoclink doesn’t work in script library

Try adding the “optional” third parameter (hot spot text) to the AppendDocLink. I have found that things don’t work right without it. It can be blank (“”), but has to be there.

Subject: RE: Appenddoclink doesn’t work in script library

Other Suggestions:ReplaceItemValue on a rich text field is unusual. Remove the item instead, and create a new one.

Call NotesRichTextItem.Update after you complete your rich text changes.

I’m not sure that will help. If not, please provide more detailed information. Specifically:

You say there is a “strange error.” Does this mean there is an error message? If so, what message exactly and on what line?

Do the other rich text changes you are making appear in the field?

By the way, saving changes to the current document on Queryclose is generally a bad idea, for performance and to avoid save/replication conflicts.

Subject: Appenddoclink doesn’t work in script library

Hi,

I had similar problem. I had a class called “MyLog” in a script library called “MyLog”. It didn’t work until I have changed the name of the script library. Maybe there can be the same problem on your site. Try to change your script library’s name, maybe it will help.

Subject: RE: Appenddoclink doesn’t work in script library

Hi,

Thank you your answare but your idea doesn’t work at me. :frowning:

Have somebady got any other idea?

Tibor

Subject: Appenddoclink doesn’t work in script library

Hi,

Thank you your answares. I solved the problem with combination of two advices.

I had to change the replaceitemvalue method to remove and create methods and I had to write the third optional parameter to appenddoclink.

Thank you once again.

T. Krivan