"After New Mail Arrives" Agent Problem

Hi,

I have an agent that runs on the above trigger, to send notifications to staff about new documents. Whilst my agent works perfectly when I test it, and seems to work at first when I progress it to live, I also find that my agent runs again overnight on the same document/s…

I thought using database.UnprocessedDocuments, and session.UpdateProcessedDoc would ensure I don’t pick up repeated documents, but it doesn’t seem to work. I’ve now added a field called “Flag” which i’ll set each time the agent runs - does this seem likely to provide the answer?

Any advice would be appreciated. I’ve read the Agent FAQ’s over and over again but I must be missing something…

Here’s the main code:

Set db=sesh.CurrentDatabase	

Set collection=db.UnprocessedDocuments

Set doc=collection.GetFirstDocument



' maildoc variable represents the e-mail we will send to PDInfo

' to inform them of new documents.....LMc

Set maildoc=New NotesDocument(db)

maildoc.Form="Memo"

maildoc.Subject="New Document In Prism Database"



While Not doc Is Nothing

	

	If doc.Flag(0)="Flagged" Then

		Goto nextdoc

	End If

	

	Dim IsNew As Integer

	IsNew=1

	

	Dim rtitem As Variant

	Set rtitem = doc.GetFirstItem( "Body")

	

	' Now find all attachments in each of the newly received

	' documents, by looking for Rich Text fields and then

	' analysing it for attachments.....LMc

	If ( rtitem.Type = RICHTEXT ) Then

		res=Evaluate("@Attachments",doc)

		If res(0)>=1 Then

			Forall o In rtitem.EmbeddedObjects

				

				' Extract every attachment to the following path. LMc

				Call o.ExtractFile("C:/Test/DATATRAN/"+o.Name)

			End Forall

		End If

	End If

	

	' Create a new Rich Text Item, append a DocLink to each new

	' document we've received, and then attach this Rich Text

	' Item to our new mail message.....LMc

	Dim rtitem2 As notesrichtextitem

	Set rtitem2 = New NotesRichTextItem( maildoc, "Body" )

	Call rtitem2.AppendDocLink( doc, "" )

nextdoc:

	' Mark the current incoming document as processed, so that

	' it isn't processed by the agent again next time it runs.....LMc

	doc.Flag = "Flagged"

	Call doc.save(True,False)

	Call sesh.UpdateProcessedDoc( doc )

	

	Set doc=collection.GetNextDocument(doc)

Wend



If collection.Count>0 And IsNew=1 Then

	Call maildoc.Send(False,"Lee McIvor")

End If

Subject: Re: “After New Mail Arrives” Agent Problem

If anything ‘touches’ & modifies the documents, they become unprocessed. This can be other agents, users (pesky things, aren’t they) or even virus software. Look at the document properties of a few of the messages and see if they are being modified.

– Do you have any other agents that might touch & modify the documents?

– Do you run antivirus software that runs with the domino server (like Symantec Antivirus for Domino, etc.)? If so, what version?

cpw…

Subject: RE: Re: “After New Mail Arrives” Agent Problem

Thanks Craig,

I knew I was missing something… I thought that, with the Unprocessed property, it wouldn’t matter if another agent/process modified the document because it would still always be Processed for that Agent. If the processes you mention make it become Unprocessed again for the same agent then that explains it!

I’ve added code to set a hidden field when the document is processed by the agent, so that should resolve it.

Thanks for your help.