0

I have an agent in LotusScript that builds a neatly formatted table of document links and descriptions that functions as a monthly reminder digest. When I run it manually (Agent-Run), it sends a perfectly formed message that matches the code.

However, when I schedule the same agent, the output loses all of the table styling as well as the appended doclinks. This makes makes the outbound email useless. The server is in the ACL as Manager with all roles checked has the same/higher permissions than my ID. In agent properties, the Security settings are level 3 to allow restricted operations with full administration rights.

Option Public Option Declare

Sub Initialize Dim session As New NotesSession Dim db As NotesDatabase Set db = session.currentdatabase Dim docs, keydocs As NotesDocumentCollection Dim keydoc, doc As NotesDocument Dim dt As New NotesDateTime(Today) Dim dtstr, key As String, svr As String, sendto As string Dim mfgview, dptview As NotesView Dim reldb As NotesDatabase Set reldb = session.Getdatabase("Server", "db.nsf") Dim relview As NotesView Set relview = reldb.Getview("(Categorized docs-Rev_ob)") Dim bkmdoc As notesdocument

Set mfgview = db.Getview("DutyRosterMaint") 'mfg dept
Set dptview = db.Getview("2-5 years dept") 'docs needed to be reviewed

Dim j, keydocct, keyct As Integer
Dim vardp, varnm As Variant
    
vardp = Evaluate({@DBColumn("":"Nocache";@DBName;"DutyRosterMaint"; 1)})'get dept name in array
keyct = UBound(vardp)

If keyct > 0 Then
    Set keydoc = mfgview.GetFirstDocument
    'Do Until keydoc Is Nothing
    For j = 0 To keyct-1
        key = vardp(j)
        varnm = Evaluate({@DBLookup("":"Nocache";@DBName;"DutyRosterMaint";"}& key &{";2;[FailSilent])})
        Set docs = dptview.Getalldocumentsbykey(key, true)
        Dim dcct, i, cellnm As Integer
        dcct = docs.count
        If dcct>0 Then
            Dim maildoc1 As New NotesDocument ( db )
            Dim rtitem1 As New NotesRichTextItem ( maildoc1, "Body" )
            Call rtitem1.AppendText ("Hello,")
            Call rtitem1.AddNewLine ( 2)                    
            Dim bodytxt As String
            bodytxt = "This is an automated monthly email. "&_
            "You are receiving this email because you are listed as the reviewer responsible for the documents below." &_ 
            Chr$(13) & Chr$(13) &_
            "The documents listed have not been revised in in 2 years (xx) or 5 years (all other types).Please determine if these documents are still necessary, accurate and suitable for use or coordinate with the appropriate individual to conduct the review." &_
            Chr$(13) & Chr$(13) &_
            "When done, the 'Set Review Date' button must be clicked on each document to reset the document review date. " &_
            Chr$(13) & Chr$(13) &_
            "If you have any questions or need assistance, please contact me or refer to BKM-0013 section VIII for additional guidance. " &_
             Chr$(13) & Chr$(13) &_
            "Thank you, "
            Call rtitem1.AppendText (bodytxt)
            Call rtitem1.AppendDocLink(bkmdoc, "xx-0013")
            Call rtitem1.AppendText( " xx-0013")
            Call rtitem1.AddNewLine ( 2)
            Dim rtnav As NotesRichTextNavigator
            Set rtnav = rtitem1.Createnavigator
            
            Dim richStyle As NotesRichTextStyle
            Set richStyle = session.CreateRichTextStyle
            richStyle.Bold = True
            richStyle.Underline = True
            richStyle.FontSize = 12
            Call rtitem1.Appendstyle(richStyle)
            Call rtitem1.AppendText (key)
            
            Set richStyle = session.CreateRichTextStyle
            richStyle.Bold = False
            richStyle.Underline = False
            richStyle.FontSize = 10
            Call rtitem1.Appendstyle(richStyle)
            Call rtitem1.AddNewLine ( 1)
            
            Dim rtt As NotesRichTextTable
            Dim styles(0 To 5) As NotesRichTextParagraphStyle
            'link
            Set styles(0) = session.CreateRichTextParagraphStyle
            styles(0).Alignment = 0
            styles(0).Firstlineleftmargin = 0
            styles(0).Leftmargin = 0
            styles(0).RightMargin = RULER_ONE_CENTIMETER * 0.7
            
            'approval date
            Set styles(1) = session.CreateRichTextParagraphStyle
            styles(1).Alignment = 0
            styles(1).Firstlineleftmargin = 0
            styles(1).Leftmargin = 0
            styles(1).RightMargin = RULER_ONE_CENTIMETER * 2
            
            'docnum
            Set styles(2) = session.CreateRichTextParagraphStyle
            styles(2).Alignment = 0
            styles(2).Firstlineleftmargin = 0
            styles(2).Leftmargin = 0
            styles(2).RightMargin = RULER_ONE_CENTIMETER * 2
            
            'title
            Set styles(3) = session.CreateRichTextParagraphStyle
            styles(3).Alignment = 0
            styles(3).Firstlineleftmargin = 0
            styles(3).Leftmargin = 0
            styles(3).RightMargin = RULER_ONE_CENTIMETER * 7.5
            
            'rev
            Set styles(4) = session.CreateRichTextParagraphStyle
            styles(4).Alignment = 0
            styles(4).Firstlineleftmargin = 0
            styles(4).Leftmargin = 0
            styles(4).RightMargin = RULER_ONE_CENTIMETER * 0.8
            
            'last editor
            Set styles(5) = session.CreateRichTextParagraphStyle
            styles(5).Alignment = 0
            styles(5).Firstlineleftmargin = 0
            styles(5).Leftmargin = 0
            styles(5).RightMargin = RULER_ONE_CENTIMETER * 4
            
            Set rtt = rtnav.Getfirstelement(RTELEM_Type_Table)
            Call rtitem1.Appendtable(dcct+1, 6,,, styles)
            
            maildoc1.Form = "Memo"
            
            If varnm(0) = "" THen
                maildoc1.SendTo = "Test"
            Else
                maildoc1.SendTo = varnm
            End if              
            
            Dim devnm(2) As Variant
                            devnm(1) = "Test"
            maildoc1.SendTo = devnm
            maildoc1.CopyTO = "Test"
            maildoc1.Subject = "Process Document Review Due for: " & key
            Set doc = docs.Getfirstdocument()
            'link
            Call rtnav.Findnthelement(RTELEM_TYPE_TABLECELL , 1)
            Call rtitem1.Begininsert(rtnav)
            Call rtitem1.AppendText("Link")
            Call rtitem1.EndInsert
            'approval date
            Call rtnav.Findnthelement(RTELEM_TYPE_TABLECELL , 2)
            Call rtitem1.Begininsert(rtnav)
            Call rtitem1.AppendText("Approval Date")
            Call rtitem1.EndInsert
            'docnum
            Call rtnav.Findnthelement(RTELEM_TYPE_TABLECELL , 3)
            Call rtitem1.Begininsert(rtnav)
            Call rtitem1.AppendText("Doc Num")
            Call rtitem1.EndInsert
            'title
            Call rtnav.Findnthelement(RTELEM_TYPE_TABLECELL , 4)
            Call rtitem1.Begininsert(rtnav)
            Call rtitem1.AppendText("Title")
            Call rtitem1.EndInsert
            'rev
            Call rtnav.Findnthelement(RTELEM_TYPE_TABLECELL , 5)
            Call rtitem1.Begininsert(rtnav)
            Call rtitem1.AppendText("Rev")
            Call rtitem1.EndInsert
            'last editor
            Call rtnav.Findnthelement(RTELEM_TYPE_TABLECELL , 6)
            Call rtitem1.Begininsert(rtnav)
            Call rtitem1.AppendText("Last Editor")
            Call rtitem1.EndInsert
            
                cellnm = 7
                For i = 1 To dcct
                    If doc.Status(0) = "Approved" then
                        'link
                        Call rtnav.Findnthelement(RTELEM_TYPE_TABLECELL , cellnm)
                        Call rtitem1.Begininsert(rtnav)
                        Call rtitem1.AppendDocLink(doc, doc.DocNum(0))
                        Call rtitem1.EndInsert
                        'approval date
                        Call rtnav.Findnthelement(RTELEM_TYPE_TABLECELL , cellnm+1)
                        Call rtitem1.Begininsert(rtnav)
                        Call rtitem1.AppendText(doc.DisplayAppDate(0))
                        Call rtitem1.EndInsert
                        'docnum
                        Call rtnav.Findnthelement(RTELEM_TYPE_TABLECELL , cellnm+2)
                        Call rtitem1.Begininsert(rtnav)
                        Call rtitem1.AppendText(doc.DocNum(0))
                        Call rtitem1.EndInsert
                        'title
                        Call rtnav.Findnthelement(RTELEM_TYPE_TABLECELL , cellnm+3)
                        Call rtitem1.Begininsert(rtnav)
                        Call rtitem1.AppendText(doc.Subject(0))
                        Call rtitem1.EndInsert
                        'rev
                        Call rtnav.Findnthelement(RTELEM_TYPE_TABLECELL , cellnm+4)
                        Call rtitem1.Begininsert(rtnav)
                        Call rtitem1.AppendText(CStr(doc.Revision(0)))
                        Call rtitem1.EndInsert
                        'last editor
                        Call rtnav.Findnthelement(RTELEM_TYPE_TABLECELL , cellnm+5)
                        Call rtitem1.Begininsert(rtnav)
                        Call rtitem1.AppendText(doc.LastEditor(0))
                        Call rtitem1.EndInsert
                    Else
                        If doc.Revision(0) > 1 Then
                            Dim reldc As NotesDocument
                            Set reldc = relview.Getdocumentbykey(doc.DocNum(0), True)
                            If Not (reldc Is Nothing) Then
                                'link
                                Call rtnav.Findnthelement(RTELEM_TYPE_TABLECELL , cellnm)
                                Call rtitem1.Begininsert(rtnav)
                                Call rtitem1.AppendDocLink(reldc, reldc.DocNum(0))
                                Call rtitem1.EndInsert
                                'approval date
                                Call rtnav.Findnthelement(RTELEM_TYPE_TABLECELL , cellnm+1)
                                Call rtitem1.Begininsert(rtnav)
                                Call rtitem1.AppendText(reldc.DisplayAppDate(0))
                                Call rtitem1.EndInsert
                                'docnum
                                Call rtnav.Findnthelement(RTELEM_TYPE_TABLECELL , cellnm+2)
                                Call rtitem1.Begininsert(rtnav)
                                Call rtitem1.AppendText("*"&reldc.DocNum(0))
                                Call rtitem1.EndInsert
                                'title
                                Call rtnav.Findnthelement(RTELEM_TYPE_TABLECELL , cellnm+3)
                                Call rtitem1.Begininsert(rtnav)
                                Call rtitem1.AppendText(reldc.Subject(0))
                                Call rtitem1.EndInsert
                                'rev
                                Call rtnav.Findnthelement(RTELEM_TYPE_TABLECELL , cellnm+4)
                                Call rtitem1.Begininsert(rtnav)
                                Call rtitem1.AppendText(CStr(reldc.Revision(0)))
                                Call rtitem1.EndInsert
                                'last editor
                                Call rtnav.Findnthelement(RTELEM_TYPE_TABLECELL , cellnm+5)
                                Call rtitem1.Begininsert(rtnav)
                                Call rtitem1.AppendText(reldc.LastEditor(0))
                                Call rtitem1.EndInsert
                            End If 
                        End If
                    End if
                    Set doc = docs.getnextdocument(doc)
                    cellnm = cellnm +6
                Next
                                    
                svr = UCase(db.Server)
                If InStr(svr, "DEV") > 0 Or svr = "" Then
                    Call rtitem1.Addnewline(1)
                    If varnm(0) = "" Then
                        sendto = "Test"
                    Else
                        sendto = "Test" 
                    End If              
                    Call rtitem1.Addnewline(3)
                Call rtitem1.AppendText( "-------------------------------------------------------------------------------------------------")
                    Call rtitem1.Addnewline(1)
                    Call rtitem1.AppendText( "Bypassed delivery for testing from being delivered to : " & sendto)
                    maildoc1.sendto = "Test"
                    Call maildoc1.Send( true ) 
                Else 
                    Call maildoc1.Send( true ) 
                End If              
            End If          
        'Set keydoc = mfgview.getnextdocument(keydoc)
        'Loop
    next    
    MsgBox "Notifications have been sent successfully." 
End If

End Sub

  • If you SAVE your result in the database instead of sending it as Mail: is the result still ugly? i guess your server is set up to send all mails as plain or something like that.... probably a virus scanner of anything else i. The path does not „trust“ your server as sender. Try to simply save the document instead if sending it... then you see: is it your code or mail routing that is malfunctionning – Tode Mar 18 '21 at 22:40
  • It might be helpful if you show your code so we can see how you are building and sending the messages. – Richard Schwartz Mar 19 '21 at 12:57
  • If I save them to the database instead of sending, they look perfectly formatted just as when I run the agent manually. – Paul Stockinger Mar 23 '21 at 16:53
  • Uploaded code. Changed out recipients with "Test" account. – Paul Stockinger Mar 23 '21 at 17:03
  • @TorstenLink, our server does not run virus scanning (takes place on another level). – Paul Stockinger Mar 23 '21 at 17:24

0 Answers0