Examples: getFirstItem method
- This agent gets an item and a rich text item for all 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) { Item subject = doc.getFirstItem("Subject"); if (subject == null) System.out.println("[ No subject ]"); else System.out.println("[ " + subject.getText() + " ]"); RichTextItem body = (RichTextItem)doc.getFirstItem("Body"); if (body == null) System.out.println("No body"); else System.out.println( body.getFormattedText(true, 0, 0)); doc = dc.getNextDocument(); } } catch(Exception e) { e.printStackTrace(); } } }
- This agent demonstrates the work-around for getting multiple items
of the same name. This is a work-around and creating multiple items
of the same name is not recommended.
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(); Item item = doc.getFirstItem("FooBar"); while(item != null) { System.out.println(item.getName() + ": " + item.getText()); item.remove(); item = doc.getFirstItem("FooBar"); } } catch(Exception e) { e.printStackTrace(); } } }