Rendertortitem and invalid or nonexistant document

I am trying to duplicate over the web the functionality that allows users to forward any document out of a database on a Notes Client. To do so, I have created an agent that passes the doc id of the doc needed to be forwarded to an agent, then the agent renders it to RT and mails it to the intended recipient.

The problem I am encountering is that when the email gets to the recipient inbox, it can’t be opened, and has the error “Invalid or Nonexistant Document”. Through the document properties I can see the Form field is set correctly and the Body field is rich text and contains the content I am looking for. So, the doc is being found, renderered to rt, and sent to the correct person. There are no references to external files in the content, but I cannot open the document. Note that when I send only plain text in the Body (for example “Hello World”) it works, but rendering to RT seems not to.

Any help/insight would be greatly appreciated. Below is the relevant part of the code from the agent that does the sending:

' create the doc that is being mailed

Set mailDoc = New NotesDocument(currdb)

mailDoc.Form = "Memo"

mailDoc.Subject = subject

Set rtitem = New NotesRichTextItem(mailDoc, "Body")



' get the document that's being forwarded and pop it into the mailing doc

Set lookupview = currdb.GetView("All By ID")

Set lookupdoc = lookupview.GetDocumentByKey(ForwardDoc)

If lookupdoc Is Nothing Then

	agentlog.LogAction "could not find doc " & ForwardDoc

	rtitem.AppendText "There was a problem mailing the requested document from QMR"

Else

	

	' convert it to RT

	lookupdoc.RenderToRTItem rtitem

End If ' end making sure we got the doc that's being forwarded



' finish up the email and send it

agentlog.LogAction "sending it"

mailDoc.SendTo = sendToString

Call mailDoc.Send(False)

Subject: rendertortitem and invalid or nonexistant document

You got to save the document, before rendering RT item. (Check help). Hence:

Set mailDoc = New NotesDocument(currdb)

mailDoc.Form = “Memo”

mailDoc.Subject = subject

Set rtitem = New NotesRichTextItem(mailDoc, “Body”)

Call mailDoc.Save(True, True)

'Get the document that’s being forwarded and pop it into the mailing doc

Set lookupview = currdb.GetView(“All By ID”)

Set lookupdoc = lookupview.GetDocumentByKey(ForwardDoc)

If lookupdoc Is Nothing Then

agentlog.LogAction "could not find doc " & ForwardDoc

rtitem.AppendText “There was a problem mailing the requested document from QMR”

Else

’ convert it to RT

Call lookupdoc.RenderToRTItem(rtitem)

End If

’ end making sure we got the doc that’s being forwarded

’ finish up the email and send it

agentlog.LogAction “sending it”

mailDoc.SendTo = sendToString

Call mailDoc.Send(False)

Subject: RE: rendertortitem and invalid or nonexistant document

Thank you for your post. You are right, I overlooked that in help. Unfortunately, after making the change it still throws the same error when I try to open the received doc. I put in a save where you indicated and then again after the RenderToRT item.

Extra note: Turns out there was an included javascript library in a subform that was hosing me, once I resolved that it worked like a charm.

Thanks again for your help!