Simple XPages example

Below is an example of using the OnTime Group Calendar API (hereafter simply API) from XPages. The API we use is a Java wrapper and using it from XPages consists of constructing an API instance, setting the so-called transport and initializing it before calls may be made against the backend. It's important to note that the Domino server executing the XPage must be allowed to run on behalf of other users. See the FAQ document on this topic on how to set this up.

The below example is a simple XPages with a button and a label with an id of lblResult. The button onclick event is set to execute the below code. Before you create the XPage make sure the API is available to the XPage (see Making the OnTime Group Calendar API Java wrapper available to XPages).

The below example initializes the API and reads three pieces of user information for the currently logged in user (OnTime ID, Email and Department) and renders it in a label on the page.

// import packages 

// get abbreviated name of current user
var abbrevName = session.createName(session.getEffectiveUserName()).getAbbreviated();

// create transport for Notes
var transport = new NotesSessionApiTransport(session, null, "ontime/ontimegcapi.nsf");

// create API instance
//  - do not do a Login and Version as part of init
//  - run on behalf of the user logged in
var api = new GroupCalendar2011Api(transport)

// initialize
if (api.init("Web2011", "0.0.8")) {
   // request the Department, OnTime ID and the email address of the 
   // currently logged in user
      [ITEM.ID, ITEM.Department, ITEM.Email], // items to load 
      IGroupCalendar2011Api.ID_TYPE.DN, // look up based on Notes distinguished name
      [abbrevName] // array of names to look up

   // process bloking - must be blocking
   var json = api.processBlocking(); 
   // verify the response went well
   if (json.get("Status").getStr() == "OK") {
      // if went well - define function to get an item
      var getItem = function(itemname) {
      return json.get("UsersInfo").get("Users").get(abbrevName).get(itemname).getStr();
   // define result
   var result = "User info for <" + abbrevName + 
      "> - ID <" + getItem("ID") + ">, Department <" + 
      getItem("Department") + ">, Email <" + 
      getItem("Email") + ">";
   } else {
      // unable to load data
      var result = "Unable to load user info for <" + 
         abbrevName + "> due to error <" + 
         json.get("Error").getStr() + ">";

// get component and show result

Tuesday, 28 October 2014 Posted in Development