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