JAVA/CORBA CLASSES
Examples: getDocumentByUNID method
1. This agent gets the parents of all the response documents 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();
DocumentCollection dc = db.getAllDocuments();
Document doc = dc.getFirstDocument();
while (doc != null) {
if (doc.isResponse()) {
Document pdoc =
db.getDocumentByUNID(doc.getParentDocumentUNID());
String docSubj = doc.getItemValueString("Subject");
String pdocSubj = pdoc.getItemValueString("Subject");
System.out.println("\"" + pdocSubj +
"\" has the response \"" + docSubj + "\"");
}
doc = dc.getNextDocument(doc);
}
} catch(Exception e) {
e.printStackTrace();
}
}
}
2. This agent demonstrates catching NotesError.NOTES_ERR_BAD_UNID. The UNID is deliberately altered to cause the error.
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) {
if (doc.isResponse()) {
String docSubj = "";
try {
docSubj = doc.getItemValueString("Subject");
// Deliberately munge UNID
String badUNID = "Z" +
doc.getParentDocumentUNID().substring(1);
Document pdoc = db.getDocumentByUNID(badUNID);
String pdocSubj = pdoc.getItemValueString("Subject");
System.out.println("\"" + pdocSubj +
"\" has the response \"" + docSubj + "\"");
} catch(NotesException ne) {
if (ne.id == NotesError.NOTES_ERR_BAD_UNID)
System.out.println("Bad UNID for \"" + docSubj + "\"");
else throw ne;
}
}
doc = dc.getNextDocument(doc);
}
} catch(NotesException ne) {
System.out.println(ne.id + " " + ne.text);
} catch(Exception e) {
e.printStackTrace();
}
}
}
See Also
getDocumentByUNID method
Glossary
Feedback on
Help
or
Product Usability
?
Help on Help
All Help Contents
Glossary