Examples: logAction method
This agent logs actions to a mail memo. It performs a full-text search on the current database, and logs one action for each document that matches the full-text search query.
Each time the logAction method is called, it adds a new line to the Body item of the mail memo. For example, if FTSearch returns a collection of three documents, the body of the mail memo looks like this:
09/14/98 01:41:51 PM Botany Agent starting 09/14/98 01:41:52 PM Document [Petals] placed in folder. 09/14/98 01:41:52 PM Document [Stems] placed in folder. 09/14/98 01:41:52 PM Document [Leaves] placed in folder.
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)
Log log = session.createLog("Botany Agent");
Vector v = new Vector();
v.addElement(session.getUserName());
log.openMailLog(v, "Log for botany agent");
Database db = agentContext.getCurrentDatabase();
DocumentCollection dc = db.FTSearch("botany", 0);
Document doc = dc.getFirstDocument();
while (doc != null) {
doc.putInFolder("Botanist's Delight");
log.logAction("Document " +
doc.getItemValue("Subject") +
" placed in folder.");
doc = dc.getNextDocument();
}
log.close();
} catch(Exception e) {
e.printStackTrace();
}
}
}