DBLookup with JavaScript and XPath

This tip will perform a JavaScript DBLookup using XPath.

This code is my own version of a JavaScript DBLookup using XPath. It works with both categorized and non-categorized views. It is for Internet Explorer only.

function dbLookup(dblDatabase,
dblView,dblKey,dblColumn,dblLimit){
//David Schmidt, 2005-10-27
try{
 dblColumn=dblColumn-1;
 var xmldoc=new ActiveXObject
("MSXML2.DOMDocument");
 xmldoc.async=false;
 docLimit=(dblLimit!="")?dblLimit:"-1";
 xmldoc.load("/"+dblDatabase+"/"+dblView+"
?readviewentries&expandview⪻eFormat&count="
+docLimit);
 if(xmldoc.parseError.errorCode!=0){
  var xmlerror=xmldoc.parseError;
  errorstr="XSL error\n\nError code: "
+xmlerror.errorCode+"\nReason: "+
xmlerror.reason+"\nLine: "+xmlerror.line+"\nLine position: 
"+xmlerror.linepos+"\nsrcText: "
+xmlerror.srcText+"\nUrl:"+xmlerror.url+"\nFile position: 
"+xmlerror.filepos;
  alert(errorstr);
  return "error";
 }else{
  columnNode=xmldoc.documentElement.selectNodes
("/viewentries/viewentry/entrydata[@columnnumber='0' 
and .='"+dblKey+"']");
  dblArray=new Array();
  if(columnNode.length>0){
   if(columnNode.item(0).getAttribute("category")){
     NodePosition=
columnNode.item(0).parentNode.getAttribute("position");
     xmldoc.setProperty("SelectionLanguage", "XPath");
     xpathquery=
"/viewentries/viewentry/entrydata[starts-with
(../@position,'"+NodePosition+".') and 
@columnnumber="+dblColumn+"]";
     categoryNode= 
xmldoc.documentElement.selectNodes(xpathquery);
     for(x=0;x<categoryNode.length;x++){
      dblArray[x]=categoryNode[x].childNodes(0).text;
     }
   }else{
    for(x=0;x<columnNode.length;x++){
     dblArray[x]=
columnNode[x].parentNode.childNodes(dblColumn).text;
    }
   }
  }
  return dblArray;
}
}catch(e){
 var errName=e.name;
 var errNumber=e.number & 0xFFFF;
 var errDescription=e.description;
 errMessage=e+"\n\nName: "+errName+"\nNumber: "
+errNumber+"\nDescription: "+errDescription;
 alert(errMessage);
 return error;
}
}

Do you have comments on this tip? Let us know.

This tip was submitted to the SearchDomino.com tip exchange by member David Schmidt. Please let others know how useful it is via the rating scale below. Do you have a useful Notes/Domino tip or code to share? Submit it to our bimonthly tip contest and you could win a prize and a spot in our Hall of Fame.

This was first published in October 2005

Dig deeper on JavaScript for Lotus Notes Domino

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchWinIT

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchEnterpriseLinux

SearchVirtualDataCentre.co.UK

Close