Agents

I have created an agent that sends a message to ne person in the field ‘SendTo’ after checking the deadline criteria in forms,i.e compare the deadline with today’s date. and if the date is greater than today’s date it sends a notification.There are four forms from which it has to select field…also i want to send the document link through the agent.The code is

Sub Initialize

On Error Goto errorHandler

Dim s As New NotesSession

Dim db As NotesDatabase

Dim coll As NotesDocumentCollection

Dim collres As NotesDocumentCollection

Dim doc As NotesDocument

Dim totalquery As String	

Dim maildoc As NotesDocument

Dim ritem As NotesRichTextItem	

Dim sumofsend As Integer	

Dim agent As NotesAgent

Dim agentname As String

Dim maildb As notesdatabase	

Dim count As Integer

Dim vc As NotesViewEntry

Dim Recipients As String	

Dim richStyle1 As NotesRichTextStyle

Dim richStyle2 As NotesRichTextStyle

Dim richStyle3 As NotesRichTextStyle

Dim richStyle As NotesRichTextStyle



Set db = s.CurrentDatabase	

Set agent = s.CurrentAgent

Set maildb.getdatabase                (db.server,"mail.box")

sumofsend = 0





Set richStyle = s.CreateRichTextStyle

richStyle.NotesFont = STYLE_NO_CHANGE

richStyle.NotesColor = COLOR_BLACK	richStyle.FontSize = 10	



Set richStyle1 = s.CreateRichTextStyle

richStyle1.NotesFont = STYLE_NO_CHANGE

richStyle1.NotesColor = COLOR_BLACK	richStyle1.FontSize = 10	



Set richStyle2 = s.CreateRichTextStyle

richStyle2.NotesFont = STYLE_NO_CHANGE

richStyle2.NotesColor = COLOR_BLACK	richStyle2.FontSize = 10		

Set richStyle3 = s.CreateRichTextStyle

richStyle3.NotesFont = STYLE_NO_CHANGE

richStyle3.NotesColor = COLOR_BLACK	richStyle3.FontSize = 10		

'query to check deadline from 4 forms

totalquery = “(Form=”“Pro_event_log”" | Form = ““Bug_event_log”” | Form = ““PER_reply”” | Form = ““BE_reply”” ) & @Contains(SendTo;““domain””) & (@Date(Deadline_1)<@Today | @date(Deadline_1_1)<@today)"

Set coll = db.Search(totalquery, Nothing, 0)

For i=1 To coll.count

Set doc = coll.GetNthDocument(i)

Set collres = doc.Responses

If Not collres Is Nothing Then

If count is ‘0’

If collres.Count=0 Then Set maildoc=db.CreateDocument

maildoc.From=db.Server	

maildoc.Form="memo"

maildoc.sendto=doc.SendTo(0)

Call mailDoc.AppendItemValue(“subject”,“New Bug Event Reply Notification! Bug Title:<<” + doc.Pro_title(0) + “>>”)

Set ritem = mailDoc.CreateRichTextItem(“body”)

Call ritem.AppendText(“Complete Project ASAP!)!” + Chr(13) + Chr(10) + “System Notification!”)

Call ritem.AppendText(" Project Report by <<" + doc.Author(0) + “>>, please Check!”)

Call mailDoc.Send(False, “SendTo”)

Exit Sub	

sumofsend = sumofsend + 1

End If

End If

Next

Set mailDoc = db.CreateDocument

mailDoc.form = “memo”

agentname = agent.Name

Call mailDoc.AppendItemValue(“subject”,“User Name<” + s.CommonUserName + “>File Name<” + db.FileName + “>Agent Name<” + agentname + “>Executed”)

Set ritem = mailDoc.CreateRichTextItem(“body”)

Call ritem.AppendText(“Agent execution complete: " + Cstr(coll.count) + " Number of times the message is sent: " + Cstr(sumofsend) + " Have already sent mail to the required person!”)

Call mailDoc.Send(False, “administrator/domain”)

Exit Sub

errorHandler:

Print "Error " & Str(Err()) & " in line " & Str(Erl()) & ":" & Error$	

End Sub

the prob is

  1. I get the notification as an administrator but the agent does not pick ne field from the form,when sending a notification to ne1. Also is the agent capable of differentiating between response forms and responsetoresponse form?? because all the 4 forms are the R and R2R forms.

  2. Will count also count the response forms and response to response forms??

Subject: Agents

Sohney,

I think you problem is that you are only attempting to set up the email with fields from doc when “If collres.Count=0 Then” but that is applied after your test for "If Not collres Is Nothing Then "

ie only if there is nothing in your collection, once you have deduced that there is something in your collection, and I’m not sure whether the code would be hitting the “If collres.Count=0 Then” line.

To check whether it is, place a Msgbox “here” debug statement after your “If collres.Count=0 Then” statement

The way you have written the agent, you will only see responses to the “doc” obtained from collection “coll”. To get responses to responses, you have to iteratively look for responses to each individual response until none are obtained.

have a look at the help for doc.reponses - I seem to remember that it shows an example of such recursive agents.

Hope that helps … John Kvalheim