0

All,

I have the following problem. I want to launch an agent and want it to communicate back to the calling script if things went OK or if something went less OK.

I tried to use a solution that seems obvious, the return value of the NotesAgent.Run

My agent looks like this (Terminate sub routine is empty)

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

I am calling(or launching if you may) the agent like this

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

If I take out the Error statement the logs get updated, and that doesn't happen if I leave there the Error statement, so it is definitely causing an error. But the Message box always prints stubbornly "It returned 0". I also tried to put the Error statement on Terminate. Result was the same, unfortunately ..

Could you please kindly point me where I'm going sideways on this ? I was expecting this to be simple.

Thank you

Kind Regards, Carlos

Knut Herrmann
  • 30,880
  • 4
  • 31
  • 67
Carlos Botelho
  • 75
  • 2
  • 11

2 Answers2

2

This method returns a value that indicates that the agent is started or did not started. It does not return the result of the agent itself. If the agent is started, but during its work the agent made an error, then this method returns 0, because the agent is started.

0. To recieve a status from agent you can use the in-memory document as described here.
Your agent:

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

Call the agent like this:

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. If you cannot use in-memory document then you need to save document and reopen it.
Your agent:

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

Call the agent like this:

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
Community
  • 1
  • 1
nempoBu4
  • 6,521
  • 8
  • 35
  • 40
0

I believe you need to use the RunOnServer() method, which according to the documentation is synchronous:

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
Ken Pespisa
  • 21,989
  • 3
  • 55
  • 63