无论如何,NotesAgent.Run方法始终返回0

时间:2014-07-22 18:00:53

标签: lotus-notes lotusscript

所有

我有以下问题。我想启动一个代理,如果一切正常或者事情变得不那么好,希望它与调用脚本进行通信。

我尝试使用一个看似很明显的解决方案,即NotesAgent.Run的返回值

我的代理看起来像这样(终止子例程为空)

Sub Initialize
    Set ws = New NotesUIWorkspace
    Set uidoc = ws.Currentdocument
    Set doc = uidoc.Document
    Set pass = doc.Getfirstitem("Passcode")
    Error 1144
    ' log information here
End Sub

我正在打电话(或者如果可能的话,启动)这样的代理

Sub Click(Source As Button)
    Dim session As New NotesSession
    Dim db As NotesDatabase
    Dim agent As NotesAgent

    Set db = session.CurrentDatabase

    Set agent = db.GetAgent("MyAgent")

    returnVal% = agent.Run
    Messagebox "It returned " & returnVal%
End Sub

如果我取出Error语句,日志会更新,如果我离开Error语句就不会发生这种情况,因此肯定会导致错误。但是消息框总是固执地打印“它返回0”。我还尝试将Error语句放在Terminate上。不幸的是,结果是一样的......

请你指点一下我在旁边的地方吗?我期待这很简单。

谢谢

亲切的问候, 卡洛斯

2 个答案:

答案 0 :(得分:2)

此方法返回一个值,指示代理已启动或未启动。它不返回代理本身的结果。如果代理程序已启动,但在其工作期间代理程序发生错误,则此方法返回0,因为代理程序已启动。

0.要从代理接收状态,您可以使用here所述的内存文档 你的代理人:

Sub Initialize
    Set ws = New NotesUIWorkspace
    Set uidoc = ws.Currentdocument
    Set doc = uidoc.Document
    Set pass = doc.Getfirstitem("Passcode")

    Dim ses As New NotesSession
    Dim docContext = ses.DocumentContext
    Call docContext.ReplaceItemValue("ReturnVal", 1444)
    ' log information here
End Sub

像这样呼叫代理:

Sub Click(Source As Button)

    Dim session As New NotesSession
    Dim db As NotesDatabase
    Dim agent As NotesAgent
    Dim doc As NotesDocument

    Set db = session.CurrentDatabase
    Set doc = db.CreateDocument

    Set agent = db.GetAgent("MyAgent")

    Call agent.RunWithDocumentContext(doc)

    returnVal% = doc.ReturnVal(0)
    Messagebox "It returned " & returnVal%

End Sub


1.如果您不能使用内存文件,则需要保存文件并重新打开 你的经纪人:

Sub Initialize
    Set ws = New NotesUIWorkspace
    Set uidoc = ws.Currentdocument
    Set doc = uidoc.Document
    Set pass = doc.Getfirstitem("Passcode")

    Dim ses As New NotesSession
    Dim agent As NotesAgent
    Dim db As NotesDatabase
    Dim docContext As NotesDocument

    Set agent = ses.CurrentAgent
    Set db = ses.CurrentDatabase

    Set docContext = db.GetDocumentByID(agent.ParameterDocID) 
    Call docContext.ReplaceItemValue("ReturnVal", 1444)
    Call docContext.Save(False, False)
    ' log information here
End Sub

像这样呼叫代理:

Sub Click(Source As Button)

    Dim session As New NotesSession
    Dim db As NotesDatabase
    Dim agent As NotesAgent
    Dim doc As NotesDocument

    Set db = session.CurrentDatabase
    Set doc = db.CreateDocument
    Call doc.Save(False, False)

    noteID$ = doc.NoteID

    Set agent = db.GetAgent("MyAgent")

    Call agent.Run(noteID$)

    Delete doc

    Set doc = db.GetDocumentByID(noteID$)

    returnVal% = doc.ReturnVal(0)
    Messagebox "It returned " & returnVal%

    Call doc.Remove(True)

End Sub

答案 1 :(得分:0)

我相信您需要使用RunOnServer()方法,根据文档是同步的:

http://www.ibm.com/developerworks/lotus/library/ls-Troubleshooting_agents_ND5_6/

Sub Click(Source As Button)
    Dim session As New NotesSession
    Dim db As NotesDatabase
    Dim agent As NotesAgent

    Set db = session.CurrentDatabase

    Set agent = db.GetAgent("MyAgent")

    returnVal% = agent.RunOnServer()
    Messagebox "It returned " & returnVal%
End Sub