run (NotesAgent - JavaScript)

Runs the agent.

Defined in

NotesAgent

Syntax

run() : void

run(noteID:string) : void

Parameter Description
noteID Optional. The note ID of a document. The value is passed to the ParameterDocID property of the called agent.
Note: This parameter is new with Release 5.02.

Usage

This method runs any agent regardless of source language (simple action, formula, LotusScript®, Java).

You cannot run an agent recursively (cannot call it from itself).

The user cannot interact directly with a called agent. User output goes to the Domino® log.

You cannot debug a called agent.

For local Notes® client operations, the agent runs in the Notes® client on the computer processing the XPage. See runOnServer to do otherwise.

For remote (IIOP) operations, the agent runs on the server handling the remote calls.

Examples

This agent runs the agent named Agent to be run Java.
var agent = database.getAgent("Agent to be run Java");
agent.run()
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();
          String sn;
          if (session.isOnServer()) {
        	  sn = session.getServerName();
          } else {
        	  sn = "the Notes client";
          }
          memo.appendItemValue("Form", "Memo");
          memo.appendItemValue("Subject", 
               "Message from Java agent");
          memo.appendItemValue("Body", 
               "The agent is running as " +
               session.getUserName() + " on " + sn);
          memo.send(session.getUserName());

      } catch(Exception e) {
          e.printStackTrace();
       }
   }
}
This agent runs the Agent to be run parameter Java agent passing it the note ID of a newly created document.
// Create document containing data to be passed
var doc = database.createDocument();
doc.appendItemValue("TriggerUserName", session.getUserName());
doc.save(true, false);
// Start agent and pass NoteID of document
var agent = database.getAgent("Agent to be run parameter Java");
agent.run(doc.getNoteID());
This is the code for Agent to be run parameter 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 = 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();
       }
   }
}