This code takes 1st column of a categorised view and loop through all docs under that category then mail is sent to the department with some field values in table.
This code works fine on running manually but on scheduling table is not coming in an appropriate way on the mail.
Any guidance will be appreciated.
Sub Initialize
’ On Error Goto notifyerror
Dim session As New NotesSession
Dim db As NotesDatabase
Dim NDbView , Confview As NotesView
Dim entryA As NotesViewEntry
Dim nav As NotesViewNavigator
Dim doc,docMG As NotesDocument
Dim dc As NotesDocumentCollection
Dim rtps As NotesrichTextParagraphStyle
Set db = session.CurrentDatabase
Set rtpStyle = session.CreateRichTextParagraphStyle
Set NDbView= db.GetView("User Request \By Requester Name")
Set nav = NDbView.CreateViewNav
Set entryA = nav.GetFirst
rcptno=""
reqnm=""
reqCategory=""
While Not entryA Is Nothing
cv= entryA.ColumnValues(0) ' To get the category value which can be used as Key
Set dc = NDbView.GetAllDocumentsByKey(cv, True)
Set doc = dc.GetFirstDocument
While Not doc Is Nothing
rcptno=rcptno & Chr(10) & (doc.URLF_Req_No(0))
reqnm=reqnm & Chr(10) & (doc.Req_dbname(0))
reqCategory=reqCategory & Chr(10) & (doc.Req_Category(0))
Set doc = dc.GetNextDocument(doc)
Wend
Set memo = New NotesDocument( db )
Set rtitem = New NotesRichTextItem( memo, "Body" )
memo.Form="Memo"
memo.Subject = "Mail Test (Can be configured later)"
Call rtitem.AddNewLine( 1 )
Set richStyle = session.CreateRichTextStyle
Set color = session.CreateColorObject
'For Setting user defined color to notes color object
notesColor1 = color.SetRGB(0,0,0)
richStyle.FontSize = 10
richStyle.NotesFont = rtitem.GetNotesFont("Georgia", True)
richStyle.NotesColor = notesColor1
Call rtitem.AppendStyle(richStyle)
Call rtitem.AppendText( "Dear "+cv)
Call rtitem.AddNewLine( 2 )
Call rtitem.AppendText( "(Can be configured later)")
'REM Create table in rtitem
Dim rowCount, columnCount, iRow, icolumn As Integer
rowCount = 1
columnCount = 4
Call rtitem.AddNewline(2)
Dim styles(1 To 4) As NotesRichTextParagraphStyle
For i% = 1 To 4 Step 1
Set styles(i%) = session.CreateRichTextParagraphStyle
styles(i%).LeftMargin = 0
styles(i%).FirstLineLeftMargin = 0
styles(i%).RightMargin = RULER_ONE_INCH * 1.5
Next
Call rtitem.AppendTable(rowCount, columnCount,,RULER_ONE_INCH * 1, styles)
Dim rtnav As NotesRichTextNavigator
Set rtnav = rtitem.CreateNavigator
'populate column headings
Dim fldlst(4) As String ' number of column headings needs to match column count
fldlst(1) = "Expense Rpt No."
fldlst(2) = "Claim for Staff Member"
fldlst(3) = "Staff Code"
fldlst(4) = "Net Claim Amount"
Call rtnav.FindFirstElement(RTELEM_TYPE_TABLECELL)
For iRow = 1 To rowCount Step 1
For iColumn = 1 To columnCount Step 1
Call rtitem.BeginInsert(rtnav)
Call rtitem.AppendText(fldlst(iColumn))
Call rtitem.EndInsert
Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)
Next
Next
' Create another navigator to get the table so rows can be added, rtnav is wrong type to do this
Dim nav1 As NotesRichTextNavigator
Dim table As NotesRichTextTable
Set nav1 = rtitem.CreateNavigator
Call nav1.FindFirstElement(RTELEM_TYPE_TABLE)
Set table = nav1.GetElement
Call table.AddRow(1)
Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)
Call rtitem.BeginInsert(rtnav)
Call rtitem.AppendText(rcptno)
Call rtitem.EndInsert
Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)
Call rtitem.BeginInsert(rtnav)
Call rtitem.AppendText(reqnm)
Call rtitem.EndInsert
Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)
Call rtitem.BeginInsert(rtnav)
Call rtitem.AppendText(reqCategory)
Call rtitem.EndInsert
' Call rtitem.AppendRTItem(rtitemB )
' Call rtitem.AddNewLine( 2 )
Call rtitem.AddNewLine(3)
'richStyle.Bold = True
Call rtitem.AppendText( "Best regards ....(Can be configured later" )
Call rtitem.AddNewLine( 1 )
'richStyle.Bold = False
Call rtitem.AppendText("FromTeam ----Can be configured later")
memo.principal="ABS Team"
memo.SendTo ="XYZ"
memo.Copyto="ABC"
Call memo.Send(False)
’ End If
' Call Confview.Refresh
'----------------------------------------------------------
Set entryA = nav.GetNextCategory(entryA)
rcptno=""
reqnm=""
reqCategory=""
Wend
'notifyerror:
’ Call notifyerror()
End Sub