Examples: Document class

  1. This agent creates a document and saves it in the current 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();
          Document doc = db.createDocument();
          doc.replaceItemValue("Form", "Main Topic");
          doc.replaceItemValue("Subject", "New building");
          if (doc.save())
            System.out.println("Document created and saved");
          else
            System.out.println("Something went wrong");
        } catch(Exception e) {
          e.printStackTrace();
        }
      }
    }
  2. This agent creates a document and sends it. The document is not saved.
    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 doc = db.createDocument();
          doc.replaceItemValue("Form", "Memo");
          doc.replaceItemValue("Subject", "Reminder");
          doc.setEncryptOnSend(true);
          doc.replaceItemValue("Body",
              "A document awaits your approval in " + 
              db.getTitle() + ".");
          doc.send("Robert Smith");
        } catch(Exception e) {
          e.printStackTrace();
        }
      }
    }