Examples: Collecting all documents and unprocessed documents using Java

  1. This agent traverses all the documents in a database.
    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();
          DocumentCollection dc = db.getAllDocuments();
          Document doc = dc.getFirstDocument();
          while (doc != null) {
            System.out.println(
              doc.getItemValueString("Subject"));
            doc = dc.getNextDocument(); }
        } catch(Exception e) {
          e.printStackTrace();
        }
      }
    }
  2. This agent traverses all the unprocessed documents associated with the current agent. If the agent, for example, processes selected documents, this code traverses all selected documents.
    import lotus.domino.*;
    public class JavaAgent extends AgentBase {
      public void NotesMain() {
        try {
          Session session = getSession();
          AgentContext agentContext = 
              session.getAgentContext();
          // (Your code goes here) 
          DocumentCollection dc = 
              agentContext.getUnprocessedDocuments();
          Document doc = dc.getFirstDocument();
          while (doc != null) {
            System.out.println(
              doc.getItemValueString("Subject"));
            doc = dc.getNextDocument(); }
        } catch(Exception e) {
          e.printStackTrace();
        }
      }
    }