Examples: evaluate method

  1. This agent applies the @ProperCase @function to the Subject field in every document of the current database.
    import lotus.domino.*;
    import java.util.Vector;
    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) {
            Vector v = session.evaluate("@ProperCase(Subject)", doc);
            doc.replaceItemValue("Subject", v.firstElement());
            doc.save(true, false);
            doc = dc.getNextDocument();
          }
        } catch(Exception e) {
          e.printStackTrace();
        }
      }
    }
  2. This agent applies the @Sum @function to the Amount field (which allows multiple values) in each document.
    import lotus.domino.*;
    import java.util.Vector;
    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();
          System.out.println("Count = " + dc.getCount());
          Document doc = dc.getFirstDocument();
          while (doc != null) {
            if (doc.getItemValueInteger("Amount") != 0) {
              Vector v = session.evaluate("@Sum(Amount)", doc);
              System.out.println(v.firstElement() + " " +
              doc.getItemValueString("Subject"));
            }
            doc = dc.getNextDocument();
          }
        } catch(NotesException ne) {
          System.out.println(ne.id + " " + ne.text);
        } catch(Exception e) {
          e.printStackTrace();
        } 
      }
    }