0

手动运行的代码(右键单击并运行)它运行良好,但是当它使用调度自动运行时会出现问题。自动化时,代码运行良好,但在运行代码结束时它会失败并显示上述错误消息。

代码看起来不错,变量已按应有的方式设置,并且手动完成时代码运行良好。

Sub processJobs(dbCurrent As NotesDatabase)
Dim vwLookup As NotesView
Dim docReq As NotesDocument
Dim dtMonthAgo As New NotesDateTime(Today)
Dim dtDelDate As NotesDateTime
Dim itmDelDate As NotesItem
Dim sender As NotesName
Dim receiver As NotesName
Dim nmServer As NotesName
Dim lngNoOfDays As Long
Dim mail As Email
Dim intCount As Integer
Dim intCountFailed As Integer
Dim strSendTo As String

On Error GoTo ErrorHandler
On Error 4000 GoTo RecipientNameBlank
On Error 4294 GoTo RecipientNotInNAB

Call AgentLog.LogAction("--------- Process Job ---------")

Call dtMonthAgo.AdjustMonth( -1 )  ' set the dtMonthAgo date to one month ago
Call dtMonthAgo.Setanytime() ' remove the time component from the date

Set vwLookup = dbCurrent.Getview("JobView")
vwLookup.Autoupdate = False

Set docReq = vwLookup.Getfirstdocument()

intCount = 0
intCountFailed = 0
Do Until docReq Is Nothing
    Set itmDelDate = docReq.GetFirstItem("DeliveryDate")
    If itmDelDate.Type = 1024 Then
        Set dtDelDate = itmDelDate.DateTimeValue
        Call dtDelDate.SetAnyTime

        If dtMonthAgo.TimeDifference(dtDelDate) > 0  Then
            intCount = intCount + 1
            Set mail = New Email ' send email...
            mail.Subject = "Processed Job"
            mail.HTML = getCompletionHTML(docReq, mail.WebURL)

            Set sender = New NotesName(docReq.JobBy(0))
            Set receiver = New NotesName(docReq.DespatchTo(0))
            Set nmServer = New NotesName(dbCurrent.Server)
            If receiver.Organization = nmServer.Organization Then
                strSendTo = receiver.Abbreviated
                ' send a copy to..
                If sender.Abbreviated <> receiver.Abbreviated Then
                    mail.CopyTo = docReq.JobBy(0)
                End If
            Else
                strSendTo = sender.Abbreviated
            End If

            mail.Send(strSendTo)
            Call agentLog.LogAction(strSendTo & " - Job No: " & docReq.JobNo(0))
   flagDoc:
            ' flag the job...
            Call docReq.Replaceitemvalue("CompletionJob", "Y")
            Call docReq.Replaceitemvalue("CompletionJobDate", Now)
            Call docReq.Save(True, False)
        End If
    End If
    Set docReq = vwLookup.Getnextdocument(docReq)
Loop

Call AgentLog.LogAction("")
Call AgentLog.LogAction("Attempted to send " & CStr(intCount) & " Job")
Call AgentLog.LogAction("Failed to send " & CStr(intCountFailed) & " Job")
Call AgentLog.LogAction("--------- End of job process ---------")

ErrorHandler:
If Not AgentLog Is Nothing Then
    Call AgentLog.LogError(Err, "errorHandler: " & CStr(Err) & " " & Error$ & " in " & LSI_Info(2))
End If
Resume getOut

23/05/2019 00:00:05 errorHandler: 91 Object variable not set in PROCESSJOBS(Object variable not set)

代理应该遍历视图,获取收件人姓名,设置变量,然后自动发送电子邮件。通过自动化,它会遍历视图并获取/设置收件人的名称,但在获取未设置对象变量的姓氏后直接失败。手动运行代码一点问题都没有,但是这段代码需要自动运行。

4

2 回答 2

2

在您的 ErrorHandler 中,记录(或打印)发生错误的行。

ErrHandler:
Print "Got error " & Error$ & " on line " & cstr(Erl)

从IBM复制的示例

于 2019-05-23T11:38:44.817 回答
1

您需要一个 Exit Sub 语句来防止您的代码进入错误处理程序。

Call AgentLog.LogAction("")
Call AgentLog.LogAction("Attempted to send " & CStr(intCount) & " Job")
Call AgentLog.LogAction("Failed to send " & CStr(intCountFailed) & " Job")
Call AgentLog.LogAction("--------- End of job process ---------")

Exit Sub ' **** You need this

ErrorHandler:
If Not AgentLog Is Nothing Then
    Call AgentLog.LogError(Err, "errorHandler: " & CStr(Err) & " " & Error$ & " in " & LSI_Info(2))
End If
Resume getOut

您似乎也没有初始化 AgentLog,尽管这可能是一个全局的。当您按计划运行它时,它是否成功地将这些行写入代理日志?如果没有,可能是在访问调度它的服务器上的代理日志数据库时出现问题。

于 2019-05-23T18:46:58.293 回答