Examples: run method

Below is "Agent to be run parameter Java." It accesses the passed NoteID through getParameterDocID, accesses the referenced document, and removes it:

  1. This agent runs the agent named "Agent to be run Java."
    import lotus.domino.*;
    
    public class JavaAgent extends AgentBase {
    
        public void NotesMain() {
    
         try {
           Session session = getSession();
           AgentContext agentContext = session.getAgentContext();
    
           // (Your code goes here) 
           Database db = agentContext.getCurrentDatabase();
           Agent agent = db.getAgent("Agent to be run Java");
           agent.run();
    
          } catch(Exception e) {
                e.printStackTrace();
            }
        }
    }

    This is "Agent to be run Java."

    import lotus.domino.*;
    
    public class JavaAgent extends AgentBase {
    
        public void NotesMain() {
    
         try {
           Session session = getSession();
           AgentContext agentContext = session.getAgentContext();
    
           // (Your code goes here) 
           Database db = agentContext.getCurrentDatabase();
           Document memo = db.createDocument();
           memo.appendItemValue("Form", "Memo");
           memo.appendItemValue("Subject", 
                "Message from Java agent");
           memo.appendItemValue("Body", 
                "The agent is running as " +
                session.getUserName());
           memo.send(session.getUserName());
    
           } catch(Exception e) {
                e.printStackTrace();
            }
        }
    }
  2. This agent runs the "Agent to be run parameter Java" agent passing it the NoteID of a newly created document.

    import lotus.domino.*;
    
    public class JavaAgent extends AgentBase {
    
        public void NotesMain() {
    
         try {
           Session session = getSession();
           AgentContext agentContext = session.getAgentContext();
    
           // (Your code goes here) 
           Database db = agentContext.getCurrentDatabase();
           // Create document containing data to be passed
           Document doc = db.createDocument();
           doc.appendItemValue("TriggerUserName", 
                    session.getUserName());
           doc.save(true, false);
           // Start agent and pass NoteID of document
           Agent agent = db.getAgent
                  ("Agent to be run parameter Java");
           agent.run(doc.getNoteID());
    
           } catch(Exception e) {
                e.printStackTrace();
            }
        }
    }

Below is "Agent to be run parameter Java." It accesses the passed NoteID through getParameterDocID, accesses the referenced document, and removes it:

import lotus.domino.*;

public class JavaAgent extends AgentBase {

    public void NotesMain() {

     try {
       Session session = getSession();
       AgentContext agentContext = session.getAgentContext();

       // (Your code goes here) 
       Database db = agentContext.getCurrentDatabase();
       Agent agent = agentContext.getCurrentAgent();
       // Get document used for passing data
       Document doc =
       db.getDocumentByID(agent.getParameterDocID());
       // Send mail containing passed data
       Document memo = db.createDocument();
       memo.appendItemValue("Form", "Memo");
       memo.appendItemValue("Subject", "Message from Java agent");
       memo.appendItemValue("Body", "The agent was started by " +
         doc.getItemValueString("TriggerUserName"));
       memo.send(session.getUserName());

       } catch(Exception e) {
            e.printStackTrace();
        }
    }
}