AppendDocLink does not append a doc link in my document

HiI have read all articles but nothing seems to help me. The following code fails to append the doclink in my document. The Body field is empty. Please see the code snippet:

Set docresults = db.CreateDocument

docresults.Form = “frmSearchResults”

Set flddoclink = docresults.GetFirstItem(“Body”)

Set docsrch = doccoll.GetFirstDocument

Do While Not docsrch Is Nothing

Call flddocLink.AddNewLine(1)

Call fldDocLink.AppendDocLink(docsrch,“link”)

Set docsrch = doccoll.GetNextDocument(docsrch)

Loop

Call docresults.Save(1,0)

Call ws.EditDocument(False, docresults)

Please help me to see where I am going wrong. Many thanks in advance.

Subject: AppendDocLink does not append a doc link in my document

Hi Tushar,

I did not look at your code (I assume it is correct ;-)), does your database has a default view?

When you send mail with a doclink the database needs a default view, otherwise the doclink will not be appended. It doesn’t really matter which view you choose.

Open the database in designer

Open a view in the database

On the second tab of the design properties select “Default when database is first openened”

Save the view

Now the mail should send with a doclink included.

Regards,

René

Subject: AppendDocLink does not append a doc link in my document

Are you sure that Body is a right text item and not just a plain text field?

ie

dim flddoclink as notesRichTextItem

set flddoclink = new notesRichTextItem( docresults, “body”)

John

Subject: Sample code - maybe it helps…

Are you trying to add multiple doclinks to your body field?If that’s the case then here’s a sample code I’m used to:

Sub Initialize

Dim session As New notessession

Dim db As notesdatabase

Dim col As notesdocumentcollection

Dim doc As notesdocument

Dim memo As notesdocument



Set db = session.CurrentDatabase

Set col = db.UnprocessedDocuments



Set memo = db.CreateDocument

memo.Form = "Memo"

Set body = New NotesRichTextItem( memo, "Body" )

memo.Subject = "The subject line of your memo goes here"



For n = 1 To col.Count

	Set doc = col.GetNthDocument(n)

	

	Call Body.AppendDocLink( doc, "Link" )

	Call Body.AddNewLine( 1 )

Next



memo.Send True, session.CommonUserName

End Sub

Good luck!

Fah

Subject: RE: AppendDocLink does not append a doc link in my document

The fact that you’re setting the Form item of the document, makes me think that this is a brand new document that you just created in this script and have never saved. Here’s a hint: the Form item is not magic. Setting it does not automatically go find that form and create all the other fields that are on it. If you want a body field, your script has to create one. You can’t just ask for it (GetFirstItem) because it doesn’t exist yet.

It seems to me your script should be terminating with an error when you try to use the variable flddoclink, whose value is Nothing. If it isn’t, I can only suppose it’s because you have an On Error statement that intercepts and ignores the error.

Subject: RE: AppendDocLink does not append a doc link in my document

Thanks for your comments, Andre. The problem is I tried it with a saved document, too but it still wudnt work. And, it didnt really flash an error. The script completes and a document is saved too albeit without the doc link.

Subject: RE: AppendDocLink does not append a doc link in my document

You need to use the debugger to step through this and see which statements it’s executing and the values of your variables. It looks like doccoll contains no documents (doccoll.Count = 0), but since you don’t show how this variable is assigned, it’s impossible to say why that is. The real problem is probably when you construct the query that you use in the Search method (or however you fill this collection).

These articles might help you: Debugging Domino Applications part 1 and part 2.