title: How to trigger the java agent from xpage button click event?
body: <p>I'd like to test java agent to clear all the documents in a view by triggering the button click event on my xpage. I have no errors in java agent, but it is not working. Could you help me out to get through this stage?</p>
  
  <p><em>Button click event:</em></p>
  
  <pre><code>var serverName=session.getCurrentDatabase().getServer();
  //@WarningMessage("current one");
  //@WarningMessage("server=" + serverName);
  //var db:NotesDatabase = session.getDatabase(session.getCurrentDatabase().getServer(), "\ProTexII.nsf");
  var db:NotesDatabase=session.getCurrentDatabase();
  @WarningMessage("db=" + db);
  
  var agent:NotesAgent = db.getAgent("SnapShotUpdate");
  @WarningMessage("agent" + agent);
  
  if (agent!=null){
  
   agent.run();
   @WarningMessage("view is fired!");
  
  }
  </code></pre>
  
  <p><em>Java agent:</em></p>
  
  <pre><code>package javaPkg;
  import java.io.PrintWriter;
  
  import lotus.domino.*;
  
  public class SnapShotUpdate extends AgentBase{
  
   public void NotesMain() {
         try {
  
           //String p = session.getPlatform();
             //PrintWriter out=getAgentOutput();
  
            System.out.println("Hello i never give it up!!");
  
  
            Session session = getSession();
            AgentContext agentContext =session.getAgentContext();
            Database db=session.getCurrentDatabase();
  
  
            //**clear view "vActualSalesFromSD" before copying documents into it
  
            DocumentCollection dc= db.createDocumentCollection();
            View view= db.getView("vActualSalesFromSD");
            Document docToBeCleared= view.getFirstDocument();
  
            while (docToBeCleared != null) {
  
               {
                  dc.addDocument(docToBeCleared);
               }
  
                  docToBeCleared = view.getNextDocument(docToBeCleared);
            }
  
            dc.removeAll(true);
         } catch(Exception e) {
           e.printStackTrace();
         }
       }
  
  
  }
  </code></pre>