Using native Notes API's - Java example


Please refer to the document describing using the OnTime Group Calendar API (here after API) using Notes native API's before reading this document (see Using the OnTime Group Calendar API using Notes native APIs (over NRPC)).

import lotus.domino.Agent;
import lotus.domino.AgentBase;
import lotus.domino.Database;
import lotus.domino.Document;
import lotus.domino.Item;
import lotus.domino.Session;
import java.util.Vector;

public class JavaAgent extends AgentBase {

   public void NotesMain() {
      try {
         // get agent session
         Session session = getSession();

         // compose request
         String request = "{\"Main\": {\"ApplVer\": \"0.0.1\", \"ApplID\": \"Web2011\", \"APIVer\": 2}}";

         // get api database, agent and document
         final Database dbApi = session.getDatabase("Solace/Krynn", "ontime/ontimegcapi.nsf");
         final Agent agentApi = dbApi.getAgent("ApiNotes");
         Document docApi = dbApi.createDocument();

         final Vector v = new Vector();
         Item item = docApi.replaceItemValue("_Authors", v);
         docApi.replaceItemValue("$Request_0", request);

         // get note id 
         final String noteid = docApi.getNoteID();
         docApi = null;

         // execute agent

         // fetch api document
         docApi = dbApi.getDocumentByID(noteid);

         // get response
         StringBuilder b = new StringBuilder();
         for (int i=0; docApi.hasItem("$Response_" + i); i++) {
            b.append(docApi.getItemValueString("$Response_" + i));

         // write response
      } catch (Exception e) {


Tuesday, 28 October 2014 Posted in Development