I have posted some of this code before for other issues which I have since been resolved with the assistance of others (thankful for that). However, I am at a total impass at this point because the prupose of this code is to send an email to adress collected in each of the documents (hence 4 emails with a subject, body part1, policy #, body part 2, and the attachment file for that same document).
For example in the view there are 4 documents and each has an email address to send to (same in each case to test), an attachment file (different for each), a policy number (different for each), etc.
While verifying the emails, I received 4 which revealed the same data (same subject, same body items, same policy number and NO attachment), and an extra email with same subject, same body items, same policy number BUT with the attachment for the same refered document from that original view.
What do I have missing here to make this work? My skill level for LS is medium and know very little about arrays. Any help would be greatly appreciated.
Thanks,
Dan
Option Public
Option Declare
Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Set db = session.CurrentDatabase
Dim dc As NotesDocumentCollection
Set dc = db.UnprocessedDocuments
Dim viewdoc As notesdocument 'viewdoc is document in doc collection
Dim ConfigView As NotesView
Dim EmailDoc As notesdocument 'EmailDoc is new document to be sent to recipient
Dim profiledoc As notesdocument 'The Profile document
Dim ConfigDoc As notesdocument 'The Profile document
Dim SubjectPart As NotesItem 'Text field in the profiledoc
Dim BodyPart1 As Variant 'RT Field in the profiledoc
Dim BodyPart2 As Variant 'RT Field in the profiledoc
Dim stRecipient As String 'Text field in the viewdoc document
Dim stPolicyNum As String 'Text field in the viewdoc document
Dim PDFAttachment As NotesRichTextItem 'The attachment field in the viewdoc document
Dim bodyField As NotesRichTextItem 'RTF body field in the EmailDoc document
Dim richStyle As NotesRichTextStyle
'Initialize agent log activity recording
Dim agentLog As New NotesLog( "Agent Log" )
Call agentLog.OpenNotesLog( "", "agentlog.nsf" )
’ LOG: number of documents to be processed
agentLog.LogAction("Number of documents processed: " & db.UnprocessedDocuments.Count)
'Set forwarding address
Set profiledoc = db.GetProfileDocument("(Database Configuration)")
Set SubjectPart = profiledoc.GetFirstItem("Subject")
Set BodyPart1 = profiledoc.GetFirstItem("Body1")
Set BodyPart2 = profiledoc.GetFirstItem("Body2")
Set richStyle = session.CreateRichTextStyle
'First - viewdoc is the document in the view collection - start cycle with the first document in view
Set viewdoc = dc.GetFirstDocument
stRecipient = viewdoc.RecipientEMail(0) 'Gets the email address from the document in the view
stPolicyNum = viewdoc.Policy(0) 'Gets the Policy number from the document in the view
While Not viewdoc Is Nothing
' LOG: nth document
agentLog.LogAction("Processed document - Policy #: " & viewdoc.Policy(0))
'Create memo
Set EmailDoc = New NotesDocument(db) 'EmailDoc is what it will be forwarded with
EmailDoc.Form = "Memo"
Set bodyField = New NOTESRICHTEXTITEM(EmailDoc, "Body")
Call EmailDoc.ReplaceItemValue( "SendTo", stRecipient )
Call EmailDoc.ReplaceItemValue( "Subject", SubjectPart )
richStyle.NotesColor = COLOR_Black
richStyle.NotesFont = STYLE_NO_CHANGE
Call bodyField.AppendStyle(richStyle)
Call bodyField.ADDNEWLINE(2)
Call bodyField.AppendRTItem(BodyPart1)'add the value of the Body1 field in the current document
richStyle.Bold = True 'start formatting text for the Policy number
Call bodyField.AppendStyle(richStyle)
richStyle.NotesColor = COLOR_Red
Call bodyField.APPENDTEXT(" ") 'add a space before the policy number
Call bodyField.APPENDTEXT(stPolicyNum) 'add the value of the Policy field in the current document
richStyle.Bold = False
Call bodyField.AppendStyle(richStyle)
richStyle.NotesColor = COLOR_Black
Call bodyField.APPENDTEXT(" ") 'add a space after the policy number
Call bodyField.AppendRTItem (BodyPart2)'add the value of the Body2 field in the current document
Call bodyField.ADDNEWLINE(2)
Call bodyField.APPENDTEXT("Thank you,") 'add a thank you note after the last paragraph
Call bodyField.ADDNEWLINE(4)
Call bodyField.APPENDTEXT("Argus ") 'add a system admin signature
%REM
Copy all fields (including RTFs) to get the attachment files to the EmailDoc document
- this is the only way to get the file attachment from backend documents
PLEASE DO NOT REMOVE THE NEXT FEW LINES
%END REM
Call viewdoc.CopyAllItems( EMailDoc, True )
'Now remove all fields that were copied over which are not necessary
Call EmailDoc.RemoveItem( "Number" )
Call EmailDoc.RemoveItem( "Policy" )
Call EmailDoc.RemoveItem( "OwnerName" )
Call EmailDoc.RemoveItem( "RecipientEMail" )
Call EmailDoc.RemoveItem( "Format" )
Call EmailDoc.RemoveItem( "EMS" )
Call EmailDoc.RemoveItem( "FaxS" )
Call EmailDoc.RemoveItem( "Incep" )
Call EmailDoc.RemoveItem( "FourDig" )
EmailDoc.SaveMessageOnSend = False
Call EmailDoc.Send(False)
Call agentLog.LogAction("Mailing the doc")
'Next - Continue cycle with the other documents in view
Call session.UpdateProcessedDoc(viewdoc)
Set viewdoc = dc.getnextdocument(viewdoc)
Wend
Call agentLog.LogAction("Agent done")
Call agentLog.Close
End Sub