Monday, May 24, 2010

XPage Error Handler

Since we do not have a lotus script debugger sort of facility in XPage, I often had difficulties in debugging server javascript code in Xpages.

Since Server Script allows lotusscript equivalent functions, Its kind of easy to debug them by creating a custom log database.

The following is How I use my log database. It is not an awesome tool. It simply helps you with print statement like feature.

var log=new Log(); //creates a log object
log.init(); //creates a log document
log.record("check point 1="+ message 1); // each of these lines

log.record("check point 1="+ message 2); // goes into consecutive lines in the
log.record("check point 1="+ message 3); // log document

you can use this with your custom functions as illustrated in the following statement,

function testMe()  {
var log=new Log(); //creates a log object
log.init("","myXpLog.nsf"); //creates a log document

 try {
  var x=session.getCommonUserName();
  log.record("check point 1="+ @UpperCase(x));

  var y=@UpperCase(x);
  log.record("check point 1="+ @ProperCase(x));the
  var z= @ProperCase(x)
 }  catch(error)  {
   log.record("Error: "+error.message);
 }  finally {

Thus you will get to log the progress of your app.

The log class that I am speaking about is defined by me as follows,

Step 1 : Include this in your script library

function Log()    {
    var xpLogDB:NotesDatabase=null;
    var logDoc:NotesDocument=null;
    var logDetails="";
    var logExists=true;
    this.init=function (
serverName,databasePath)    {
    this.record=function(detail:String)    {
    this.close = function (){
    this.deleteLog=function (){,false);
    this.logExists=function    ()    {
        return logExists;

 Create a notes database with a form named log with a field named log. Preview the database and you will be able to see any logs getting created

No comments:

Post a Comment