Auto Reply based upon a subject

I have written an auto reply agent in LS within a mail in database. It runs on a view and updates the document which after the agent runs puts the document into another view.

Now I have to make the body of the reply dynamic based upon what the subject of the email is. I have a view where the user enters in the subject and then what the reply will be. Do I use FTSearch, notes item?

Here is what I have already.

Dim session As New NotesSession

Dim doc As NotesDocument

Dim db As NotesDatabase

Dim view As NotesView

Dim reply As NotesDocument

Dim col As NotesDocumentCollection

Set db = session.CurrentDatabase

Set view = db.GetView(“Reply”)

Set col = db.UnprocessedDocuments

Set doc = col.GetFirstDocument

While Not(doc Is Nothing)

Set reply = db.CreateDocument

reply.form = “Reply”

reply.SendTo = doc.Principal(0)

reply.Subject = "RE: " & doc.Subject(0)

doc.Processed = “Yes”

Call doc.Save(False,False)

If doc.Subject(0) = "Contact Us" Then

reply.body = "Thanks" 'this is where I need it to put the dynamic body reply

		

End If

Call reply.Send(False)

Set doc = col.getnextdocument(doc)

Wend

Subject: Auto Reply based upon a subject

Cindy,

I take it the ‘body’ is in another form, and the key is the subject line.

Depending on if the ‘body’ it rich text or not, you can either use

call reply.replaceItemValue( “body”, docSubject.getItemValue( “reply”)( 0))

or if it is rich text then

set rtItem = docSubject.getFirstItem( “reply”)

set newRtItem = new richTextItem( “body”, reply)

forgot the syntax, but copy the rtItem to the newRtItem

John

Subject: RE: Auto Reply based upon a subject

Thanks for the response. I made some changes but I am getting the famous error object variable not set.

Here is my code again:

Dim session As New NotesSession

Dim doc As NotesDocument

Dim edoc As NotesDocument

Dim db As NotesDatabase

Dim view As NotesView

Dim eview As NotesView

Dim reply As NotesDocument

Dim col As NotesDocumentCollection

Dim resp As Variant

Dim subj As Variant

Dim key As String

Set db = session.CurrentDatabase

Set view = db.GetView(“Reply”)

Set col = db.UnprocessedDocuments

Set doc = col.GetFirstDocument

'get view for reply responses

Set eview = db.GetView(“AutoResp”)

While Not(doc Is Nothing)

'need to get the subject from the document

key = doc.Subject(0)

Set edoc = eview.GetDocumentByKey(key)

subj = edoc.GetitemValue(“Subject”) 'debugger stops on this line with error object variable not set

If key = subj Then

resp = doc.GetItemValue(“ReplyMessage”)

End If

'compose reply

Set reply = db.CreateDocument

reply.form = “Reply”

reply.SendTo = doc.Principal(0)

reply.Subject = "RE: " & subj

reply.Body = resp

'mark the doc so it will not respond again to

doc.Processed = “Yes”

Call doc.Save(False,False)

Call reply.Send(False)

Set doc = col.getnextdocument(doc)

Wend

Subject: RE: Auto Reply based upon a subject

Cindy,

are you option explicit or Option declare in the Option statement.

You should use…

Set edoc = eview.GetDocumentByKey(key, true)

Are you sure the view AutoResp is sorted by the first column?

John

Subject: RE: Auto Reply based upon a subject

Thanks for all the suggestions, I have it working now perfectly.

I am posting my full code in case anyone else would like to use.

Dim session As New NotesSession

Dim doc As NotesDocument

Dim edoc As NotesDocument

Dim db As NotesDatabase

Dim view As NotesView

Dim eview As NotesView

Dim reply As NotesDocument

Dim col As NotesDocumentCollection

Dim resp As Variant

Dim subj As Variant

Dim key As Variant

Set db = session.CurrentDatabase

Set view = db.GetView(“Reply”)

Set col = db.UnprocessedDocuments

Set doc = col.GetFirstDocument

'get view for reply responses

Set eview = db.GetView(“AutoResp”)

While Not(doc Is Nothing)

'need to get the subject from the document

key = doc.Subject(0)

Set edoc = eview.GetDocumentByKey(key)

If Not(edoc Is Nothing) Then

'subj = edoc.GetitemValue(“Subject”)

subj = edoc.Subject(0)

Else

Print “No subject match”

Exit Sub

End If

If key = subj Then

resp = edoc.GetItemValue(“ReplyMessage”)

End If

'compose reply

Set reply = db.CreateDocument

reply.form = “Reply”

reply.SendTo = doc.Principal(0)

reply.Subject = "RE: " & subj

reply.Body = resp

doc.Processed = “Yes”

Call doc.Save(False,False)

Call reply.Send(False)

Call view.Refresh

Set doc = col.getnextdocument(doc)

Wend

Thanks again