Examples: getLastDocument and getPrevDocument methods (DocumentCollection - Java)

  1. This agent gets all the documents in a document collection in reverse order, demonstrating the preferred loop structure.
    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 tmpdoc;
          Document doc = dc.getLastDocument();
          while (doc != null) {
            System.out.println(doc.getItemValueString
            ("Subject"));
            tmpdoc = dc.getPrevDocument();
            doc.recycle();
            doc = tmpdoc;
          }
        } catch(Exception e) {
          e.printStackTrace();
        }
      }
    }
  2. This agent gets the next to the last document in a document collection by using the last document as a parameter to getPrevDocument.
    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();
          if (dc.getCount() > 1) {
            Document doc = 
            dc.getPrevDocument(dc.getLastDocument());
            System.out.println("Doc # n-1: " +
            doc.getItemValueString("Subject")); }
        } catch(Exception e) {
          e.printStackTrace();
        }
      }
    }