Question about agent?

Hi all,

My question is can I run an agent once, on only newly created documents?

My agent runs on documents in a specific view “Freedownloadforagent”.

My agent runs well on newly created documents and the check is also good. It only runs on documents which have value “NO” in field txtEmailsent.

But whenever a document is adapted, a new email is sent for the changed document. However the field txtEmailsent is “No”. I don’t understand this.

My current agent properties are: shared agent, on schedule “daily”, target on “new & modified documents”.

Should I add something more in my code? Should I choose a different setting for the agent? Thanks, Hasan

I created an agent. This is the code in it:

Sub Initialize

Dim s As New notessession

Dim view As notesview

Dim doc As notesdocument

Dim maildoc As notesdocument

Dim item As notesitem

Dim rtitem As notesrichtextitem

Dim rtitemhelp As notesrichtextitem

Set db =s.currentdatabase

Set view=db.getview("Freedownloadforagent")

Set doc= view.getfirstdocument 

While Not doc Is Nothing

	

	If (doc.txtEmailsent(0) = "NO") Then

		

		Set maildoc= db.createdocument

		Set item= maildoc.replaceitemvalue("form","Memo")

		Set item= maildoc.replaceitemvalue("Subject","New Subscription Free Download")

		Set rtitem= New NotesRichTextItem(maildoc,"body")          

		Call rtitem.appendtext("Hello,")

		Call rtitem.AddNewLine(2)

		Call rtitem.appendtext("A subscription form is filled in at our Website!!!")

		Call rtitem.AddNewLine( 2)

		

		Call rtitem.appendtext("Salutation :  ")

		Call rtitem.appendtext(doc.dlgSalutation(0))

		

		Call rtitem.AddNewLine( 1)

		Call rtitem.appendtext("Name :  ")

		Call rtitem.appendtext(doc.txtName(0))  

		

		Call rtitem.AddNewLine( 1)

		Call rtitem.appendtext("Firstname :  ")

		Call rtitem.appendtext(doc.txtFirstname(0))  

		

		Call rtitem.AddNewLine( 1)

		Call rtitem.appendtext("Company :  ")

		Call rtitem.appendtext(doc.txtCompany(0))  

		

		Call rtitem.AddNewLine( 1)

		Call rtitem.appendtext("Country :  ")

		Call rtitem.appendtext(doc.dlgCountry(0))  

		

		Call rtitem.AddNewLine(1)

		Call rtitem.appendtext("Document link :  ")

		Call rtitem.AppendDocLink ( doc, doc.Subject( 0 ) & " Look in view " & view.Name )

		Call rtitem.AddNewLine( 2)

		

		Select Case doc.dlgCountry(0)

		Case "Netherlands"

			Call maildoc.send(True, "test1@hotmail.com")

		

		Case "België"

			'Call maildoc.send(True, "test2@hotmail.com")

		

		Case "Belgique"

			Call maildoc.send(True, "test3@hotmail.com")

		

		Case "France"

			Call maildoc.send(True, "test4@hotmail.com")

		

		Case "Germany"

			Call maildoc.send(True, "test5@hotmail.com")

		

		Case "Luxembourg"

			Call maildoc.send(True, "test6@hotmail.com")

		

		Case "Austria"

			Call maildoc.send(True, "test7@hotmail.com")

		

		Case "Suisse"

			Call maildoc.send(True, "test8@hotmail.com")

		

		Case "Schweiz"

			Call maildoc.send(True, "test9@hotmail.com")

		

		Case Else

			Call maildoc.send(True, "test10@hotmail.com")

		

		End Select

		

		

		

	End If			

	Call doc.ReplaceItemValue("txtEmailsent","YES")

	Call doc.Save(True,True)

	Set doc=view.getnextdocument(doc)

	

Wend

End Sub

Subject: Question about agent?

Try Call doc.txtEmailSent = “YES” instead of Call doc.ReplaceItemValue(“txtEmailsent”,“YES”)

Code looks OK but is the field txtEmailSent editable? If it is a computed field then it will be reset whenever it is edited. I know it is obvious but it is worth checking.