I want to run a Java agent from node.js via the proton interface. Sadly I can't get the Agent Context to work
Node.js Code
async function callEvalAgent(query) {
const agent = await db.useAgent({ name: "search" });
console.log("got the agent");
const requestDocUNID = await db.createDocument({
document: {
Form: "searchRequest",
query
}
});
console.log("queryDoc created");
console.log(requestDocUNID);
await agent.run({
selection: { search: { query: "Form = 'document'" } },
context: { unid: requestDocUNID }
});
...
}
Output:
got the agent
queryDoc created
B72CA8819EDA0691C1258592003BFBE5
...
Agent Code
public class JavaAgent extends AgentBase {
public void NotesMain() {
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
Document requestDoc = agentContext.getDocumentContext();
String query = requestDoc.getItemValueString("query");
...
} catch(Exception e) {
System.out.println("bla");
e.printStackTrace();
}
}
}
When running the code I get a NullPointerException at
String query = requestDoc.getItemValueString("query");
on the Domino Server due to the agentContext being null. If I check on it afterwards by hand the document with the given UNID is present in my view.
What did I do wrong? Used the same approach as in the HCL Example here
The documentation should be more clear.
The documentation should say that the optional document that is provided to the Agent is available to the agent using the
ParameterDocID.In a Java agent do something like this:
In a LotusScript agent do something like this: