Examples: refresh method
- This agent displays the entry count of an uncategorized view before
and after creating a document that appears in the view. The count
is the same because the view is not refreshed after creating the document.
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(); View view = db.getView("All"); System.out.println("Entries = " + view.getTopLevelEntryCount()); Document doc = db.createDocument(); doc.appendItemValue("Form", "Main Topic"); doc.appendItemValue("Subject", "New document"); doc.save(); /* Entry count is the same because the view is not refreshed */ System.out.println("Entries = " + view.getTopLevelEntryCount()); } catch(Exception e) { e.printStackTrace(); } } }
- This agent displays the entry count of an uncategorized view before
and after creating a document that appears in the view. The count
is incremented because the view is refreshed after creating the document.
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(); View view = db.getView("All"); System.out.println("Entries = " + view.getTopLevelEntryCount()); Document doc = db.createDocument(); doc.appendItemValue("Form", "Main Topic"); doc.appendItemValue("Subject", "New document"); doc.save(); view.refresh(); /* Entry count is incremented because the view is refreshed */ System.out.println("Entries = " + view.getTopLevelEntryCount()); } catch(Exception e) { e.printStackTrace(); } } }
- This agent refreshes the view before retrieving a document from
it if the view was modified.
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(); // Open view and sleep for 10 seconds View view = db.getView("By Category"); sleep(10000); // Meanwhile someone else may have modified the view view.refresh(); // Do your work Document getdoc = view.getDocumentByKey("Latest news"); if (getdoc == null) System.out.println("getdoc is null"); else System.out.println(getdoc.getItemValueString("Subject")); } catch(Exception e) { e.printStackTrace(); } } }