Hi
I have created an agent with this code to send mail.But after clicking on doclink i got error as “Linked document cannot be found in view”. I am new to notes. please help.
Dim session As New NotesSession
Dim db As NotesDatabase
Dim newdoc As NotesDocument
Dim doc As NotesDocument
Set db=session.CurrentDatabase
Set newdoc= New NotesDocument(db)
Set doc=session.DocumentContext
newdoc.Form = "Memo"
newdoc.Subject="Request to the 1st approver"
newdoc.SendTo="receiver"
Dim item As NotesRichTextItem
Set item = New NotesRichTextItem(newdoc,“body”)
item.AppendText ("For more details Click here")
item.AddNewline(2)
Call item.AppendDocLink(doc,"body")
Call doc.Save(True,False)
newdoc.Send(True)
thanks in advanced.
Subject: About Running agent on web
HiThe problem is that you are making a document link to context document. In a notes environment this is the document you are working on but on the web this is a temporary document containing CGI variables and other stuffs. This document will disappear after agent has run so that is why you get the “Linked document cannot be found in view” (to be honest I do not know if the save thing will make a difference). What you would like to do (I think) is to fetch a document in the database and send that link to the recipients. In order to do so you have to get the document and one way of doing so is to send the documentUNID with the request to the agent.
For example:
If the request to the agent is
/bla.nsf/mailAgent?openagent&docID= 0ECE8CEB92B28418C125729A004FF878
Sub Initialize
Dim db As NotesDatabase
Dim newdoc As NotesDocument
Dim doc As NotesDocument
' You forgott the NEW statement before NotesSession:)
Dim session As New NotesSession
Set db=session.CurrentDatabase
Set newdoc= db.CreateDocument
Set doc=session.DocumentContext
Dim docToMail As NotesDocument
Dim unid As String
Dim unidpair As Variant
Dim NameValuePairs As Variant
NameValuePairs = Split(doc.Query_String_Decoded(0),"&")
' You SHOULD have some sort if indata validation
unidpair = Split (Cstr(NameValuePairs(1)),"=")
' You SHOULD have some sort if indata validation
Set docToMail = db.GetDocumentByUNID(unidpair(1))
newdoc.Form = "Memo"
newdoc.Subject="Request to the 1st approver"
‘Some indata validation is needed here as well!!!
newdoc.SendTo= docToMail.nextRecipientInWorkflow(0)
Dim item As NotesRichTextItem
Set item = New NotesRichTextItem(newdoc,"body")
Call item.AppendText ("For more details Click here")
item.AddNewline(2)
Call item.AppendDocLink(docToMail,"body")
'Call doc.Save(True,False)
Call newdoc.Send(True)
End Sub
I hope it work.