例: runOnServer method

  1. 次のエージェントは、「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");
           if (agent.runOnServer() == 0)
              System.out.println("Agent ran");
           else
              System.out.println("Agent did not run");
    
           } catch(Exception e) {
                e.printStackTrace();
            }
        }
    }

    次に、「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. 次のエージェントはエージェント「Agent to be run parameter Java」を実行し、新規に作成した文書の NoteID を渡します。
    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");
           if (agent.runOnServer(doc.getNoteID()) == 0)
                System.out.println("Agent ran");
           else
                System.out.println("Agent did not run");
    
            } catch(Exception e) {
                e.printStackTrace();
            }
        }
    }

    次に、「Agent to be run parameter Java」を示します。このエージェントは、渡された NoteID に getParameterDocID を使用してアクセスし、参照文書にアクセスして削除します。

    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();
            }
        }
    }