Hi all. Need a tweak on my LS agent that is hopefully obvious to some. I have a scheduled Simple Action agent for documents in a select view that performs 3 separate actions. One of these actions is a LS agent that composes an email harvesting the addressee and custom body text. This LS agent alone works fine when run on selected doc from Action menu. It also works when part of the scheduled Simple Action agent, BUT it'll email only the first doc in the view (while the rest of the actions perform on all the docs in the view. My LS code below, and feel like UnprocessedDocuments and/or GetFirstDocument is the culprit? Don't think I'm not looking to loop anything here, as the Simple Action agent is acting on each doc. But the LS email acts only one one.
The ultimate goal is to send an email whenever a new document is created in the database, customized SendTo and Body from document contents. Can accomplish 90% of this w/o LS, but Formula does not work with "Send on Behalf" agent property, and the Send Mail Message action does not allow for Formula text for body (though it does for To, cc:, bcc: and Subject - not Body). Thanks for any insight.
Sub Initialize
Dim Session As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim dc As NotesDocumentCollection
Set db = session.CurrentDatabase
Set dc = db.UnprocessedDocuments
Set doc = dc.GetFirstDocument
Dim memo As NotesDocument
Set memo = New NotesDocument( db )
Dim bodytext As Variant
bodytext = doc.GetItemValue( "body_field" )
Call memo.ReplaceItemValue( "Body", bodytext )
Call memo.ReplaceItemValue( "Subject", _
"plain text Subject" )
Call memo.ReplaceItemValue( "Form", "Memo" )
Dim EmailTo As Variant
EmailTo = doc.GetItemValue( "Email_Address" )
Call memo.Send( False, _
EmailTo )
End Sub