1
votes

I have a java-agent from which I can call another agent with the parameter passed through it which contains NoteId, and using that NoteId, I am successfully able to get the work done the that document.Till here every thing is clear.

The main question regarding this is , Is it possible to run the agent of another database on same server from the current database agent?

To be more clear for an example I have two databases, "ABC.nsf" and "XYZ.nsf", JavaAgent "A" is in "ABC.nsf" and JavaAgent "B" is in "XYZ.nsf". In my xpage I have a button running Agent "A", and even Agent "A" can run any other javaAgent from the same database.

Code:

 Document mainDoc = db.getDocumentByUNID(tempDoc.getItemValueString("mainDocId"));
 String noteID = mainDoc.getNoteID();
 String agentName = "NotificationManager";
 Agent agent = db.getAgent(agentName);
 if (agent != null) 
     agent.runOnServer(noteID);
 else 
    System.err.println("Something is wrong");

But Actually I want run the JavaAgent "B" Located in "XYZ.nsf" from JavaAgent "A" which is in "ABC.nsf".

After some research I have referd this code. Code

Database db=session.getDatabase(current_server, "path/to/XYZ.nsf"); 
Agent myAgent=db.getAgent("B"); 
myAgent.run(); 

And yes I am unsuccessfull there, Need some idea to acheive this.Any suggession will be really appretiated.

2
Did you really write db=session.getDatabase(current_server, path/to/XYZ.nsf); or did you use quotes like this : db=session.getDatabase(current_server, "path/to/XYZ.nsf");? And: does the variable current_server contain the right servername? And: Is this a linux- server or a windows server (slash or backslah)? is the path relative to data directory? - Torsten Link
oh sorry it typing mistake i have written "path/to/XYZ.nsf". - Ajit Hogade
please share exact error message/exception stacktrace you get - Frantisek Kossuth

2 Answers

3
votes

The example code is correct in principle. Just some things you have to know:

First of all the name of server can either be "" or the real name of the server. BUT if there is a server, then you have to check the Trusted servers:- section in the server document (Security Tab - Server Access section). There the server himself has to be member of the field (as name or in a group), otherwise you might not be able to open the other database.

Second thing: the path to the target database is relative to data directory and has to be in the right format for the given operating system.

e.g. C:\IBM\Domino\Data\first\xyz.nsf would be first\xyz.nsf and /local/notesdata/second/abc.nsfwould be second/abc.nsf

Third: the noteid that you get is from a document from the calling database. In the "target"- agent you have to go and get the document from the source database, otherwise it will either throw an error or -as the noteid is just a sequential number- return a document from target database that has nothing to do with the document you are searching for.

The calling agent A would have code like this:

Session session = getSession();
AgentContext agentContext = 
session.getAgentContext();
Database dbCurrent = agentContext.getCurrentDatabase();
Database dbTarget = session.getDatabase(dbCurrent.Server, "XYZ.nsf"); 
Agent myAgent=dbTarget.getAgent("B"); 
myAgent.runOnServer(noteID); 

The called agent B could look like this

Session session = getSession();
AgentContext agentContext = 
session.getAgentContext();
Database dbCurrent = agentContext.getCurrentDatabase();
Database dbSource = session.getDatabase(dbCurrent.Server, "ABC.nsf"); 
Document doc = dbSource.getDocumentByID(agentContext.getCurrentAgent().getParameterDocID())

This should work (if security is ok on the server). As Paul mentioned in the comments security also means that the agent signer or web user (depending on the settings in agent A) has to have sufficient access to the target database AND the target server (if it is different).

If it does not work despite of correct security: Show us the exact error / trace.

0
votes

May I suggest a different approach? If you don't need an immediate reply from the agent, as a return value in the code, why don't you send the other database a special mail? Create a mail agent (triggered after new mail has been received), at the sender side create a NotesDocument object, add the values you need to reference the document you want the agent to work on, like the name of the server, the replicaId of the database, and the uniqueId. The agent receives the mail and inspects the fields for what it's supposed to do. The receiving database should be mentioned in the N&A book as Mail-in database.

Advantages are manifold: no hassle with rights, a clear interface, no need to open the other database, the agent is executed by the agent manager at a convenient time, you can easily add more functionality the same way, etc.