Search code examples
lotus-noteslotus-dominolotusscriptlotuslotus-formula

Exception in agent.runonserver in lotus notes


I have the code which calls java agent from lotusscript agent

Sub insertDealDetails() 
    On Error GoTo errhandler
    MsgBox "inside deal details"
    Dim agent As NotesAgent
    On Error GoTo errhandler
    Set agent = db.GetAgent("Procs")
    If agent.RunOnServer(doc.Noteid) = 0 Then
        MessageBox "Agent ran",, "Success"
    Else
        MessageBox "Agent did not run",, "Failure"
    End If
    Exit Sub

errhandler:
    MsgBox  "Error in function insertDealDetails in agtSubmit Agent" & Erl & Error

End Sub

Now if any exception occurs in Procs agent,how the main agent calling insertDealDetails() can be supplied with exception so that it stops the main agent.


Solution

  • Use an In-Memory Document,
    write your error message into this document in Java agent and
    read the error message in LotusScript code.

    LotusScript

    Call agent.RunWithDocumentContext(doc)
    If doc.ErrorMessage(0) <> "" Then
        print doc.ErrorMessage(0)
        ' handle the error
    End If
    

    Java agent

    Document doc = agentContext.getDocumentContext();
    ...
    doc.replaceItemValue("ErrorMessage", "Your Error Message from Java Agent");
    

    You don't need to save the In-Memory document at any time.