Reputation: 495
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.
Upvotes: 2
Views: 1227
Reputation: 495
The working code with steps for the same is as follows:
%REM
Sub insertDetailsOracle
Description: To insert details in Oracle Table
Date: 28/03/2014
'******************* Logic ***************************
'Validation In submit agent
'1)Create in-memory document
'2)Run java agent with Runwithdocumentcontext passing newly created in-memory document
' as well as note-id of original request document context
'If pass i.e. no exceptions in Java agent
'1) submit the Case
'Else
'1) Log Error message and exit the agent
'***************************************************
%END REM
Function insertDetailsOracle() As String
On Error GoTo errhandler
Dim agent As NotesAgent
Dim agentValue As Boolean
Set agent = db.GetAgent("Procs")
'Create in-memory document
Set in_doc = db.createDocument()
'Running java agent with Runwithdocumentcontext
agentValue = agent.Runwithdocumentcontext(in_doc,doc.Noteid)
'Return error message as per message passed by java agent in in-memory document's field
If in_doc.ErrorMessage(0)<>"" Then
insertDealDetails = in_doc.ErrorMessage(0)
Else
insertDealDetails = "1"
End If
Exit Function
errhandler:
MsgBox "Error in function insertDealDetailsOracle in agtSubmit Agent" & Erl & Error
End Function
The java method will be same as below.
Upvotes: 0
Reputation: 30960
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.
Upvotes: 3
Reputation: 495
it is updated code
`Sub insertDealDetails()
On Error GoTo errhandler
MsgBox "inside deal details"
Dim agent As NotesAgent
Dim in_doc As Notesdocument
On Error GoTo errhandler
Set agent = db.GetAgent("Procs")
Set in_doc = db.createDocument()
If agent.Runwithdocumentcontext(in_doc,doc.Noteid) Then`
MsgBox "doc.ErrorMessage(0):::::::::"&in_doc.ErrorMessage(0)
If in_doc.ErrorMessage(0)<>"" Then
Call prompt("2")
End If
End If
Exit Sub
errhandler:
MsgBox "Error in function insertDealDetails in agtSubmit Agent" & Erl & Error
End Sub
the problem now here is it is not returning from java code called in Procs
agent.What i will be doing wrong here.
public class JavaAgent extends AgentBase {
public void NotesMain() {
Connection con = null;
CallableStatement stmt = null;
Database db;
lotus.domino.Document doc = null;
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
doc = agentContext.getDocumentContext();
con = JavaAgent.getConnection(); //making connectiion here
//executing code here and exception occurs
System.out.println("success");
} catch(Exception e) {
try {
doc.replaceItemValue("ErrorMessage", e.getMessage());
} catch (NotesException e1) {
e1.printStackTrace();
}
e.printStackTrace();
}finally{
try {
stmt.close();
con.close();
} catch (SQLException e) {
try {
doc.replaceItemValue("ErrorMessage", e.getMessage());
} catch (NotesException e1) {
e1.printStackTrace();
}
e.printStackTrace();
}
}
}
}
The logs for the same is as follows:
**[0DCC:01AD-053C] 01/27/2016 01:24:56 PM HTTP JVM: class load: JavaAgent from: <unknown>
[0DCC:04B2-199C] 01/27/2016 01:24:56 PM HTTP JVM: before connection:::::
[0DCC:04B2-199C] 01/27/2016 01:24:56 PM HTTP JVM: inside dobi
[0DCC:04B2-199C] 01/27/2016 01:24:56 PM HTTP JVM: inside dobi 2
[0DCC:04B2-199C] 01/27/2016 01:25:28 PM HTTP JVM: inside dobi 3
[0DCC:04B2-199C] 01/27/2016 01:25:28 PM HTTP JVM: after connection:::::Oracle Database 11g Release 11.1.0.0.0 - Production
[0DCC:04B2-199C] 01/27/2016 01:25:28 PM HTTP JVM: message is Invalid column index
[0DCC:04B2-199C] 01/27/2016 01:25:28 PM HTTP JVM: java.sql.SQLException: Invalid column index
[0DCC:04B2-199C] 01/27/2016 01:25:28 PM HTTP JVM: at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125)
[0DCC:04B2-199C] 01/27/2016 01:25:28 PM HTTP JVM: at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:162)
[0DCC:04B2-199C] 01/27/2016 01:25:28 PM HTTP JVM: at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:227)
[0DCC:04B2-199C] 01/27/2016 01:25:28 PM HTTP JVM: at oracle.jdbc.driver.OraclePreparedStatement.setStringInternal(OraclePreparedStatement.java:4596)
[0DCC:04B2-199C] 01/27/2016 01:25:28 PM HTTP JVM: at oracle.jdbc.driver.OracleCallableStatement.setString(OracleCallableStatement.java:4249)
[0DCC:04B2-199C] 01/27/2016 01:25:28 PM HTTP JVM: at JavaAgent.NotesMain(Unknown Source)
[0DCC:04B2-199C] 01/27/2016 01:25:28 PM HTTP JVM: at lotus.domino.AgentBase.runNotes(Unknown Source)
[0DCC:04B2-199C] 01/27/2016 01:25:28 PM HTTP JVM: at lotus.domino.NotesThread.run(Unknown Source)
[0DF8:000A-0F84] Router: DNS server returned an error searching for MX records. The destination domain may not exist: 11.17.108.223, Error: Not implemented(NOTIMP)**
Upvotes: 0