@DBLookup function for Web

@DBLookup function for Web

An alternative to simulate @DBLookup in the Web browser and to transfer the processing of the data to the

VIEW MEMBER FEEDACK TO THIS TIP

    Requires Free Membership to View

    Register today to access targeted resources from our editorial writers and independent industry experts focused on Lotus Domino, Notes, Workplace and other related technologies.

    By submitting your registration information to SearchDomino.com you agree to receive email communications from TechTarget and TechTarget partners. We encourage you to read our Privacy Policy which contains important disclosures about how we collect and use your registration and other information. If you reside outside of the United States, by submitting this registration information you consent to having your personal data transferred to and processed in the United States. Your use of SearchDomino.com is governed by our Terms of Use. You may contact us at webmaster@TechTarget.com.

Web browser. The return of the data is a Lotus Notes Domino array.

Note: This is only available for Internet Explorer.

Example of the call:

cars = dbLookup("domino01",
"app/cars.nsf","vLookupCars","Audi",1);

          for (var i = 0; i < cars.length; i++)
                  {
                  alert("Values from lookup 
["+String(i)+"] = "+cars[i]);
                }
function dbLookup(server,path,view,
chave,column){
        // server e path optional

        xmlDoc = new ActiveXObject
("Microsoft.XMLDOM");
        xmlDoc.async = false;

        if (server != "") server = "http://"+ server;
        if (path != "") path = "/"+path +"/";

        vurl = trim(server)+trim(path)+view+
"?readviewentries&count=10000";

        xmlDoc.load(vurl);

nodes = xmlDoc.documentElement.childNodes;

        temp = new Array(nodes.length);
        var j = 0;
          for (var i = 0; i < nodes.length; i++)
                  {
                          if(nodes.item(i).
childNodes.item(0).text==chave)

                          {
                          temp[j] =
nodes.item(i).childNodes.item(column).text;
                           j++;
                          }
                }

        volta = new Array(j);
          for (var i = 0; i < j; i++)
                  {
                          volta[i] = temp[i];
                }

                return(volta);
        }

function trim(sStr)
{
  var iI = 0;
  var iJ = 0;
  var iTam = 0;
  var sAux = "";

  iTam = sStr.length;
  if(iTam==0) return(sStr);

  for(iI=0; iI<iTam; iI++)
    if(sStr.charAt(iI)!=' ') break;

  if(iI >= iTam) return("");

  for(iJ=iTam - 1; iJ>=0; iJ--)
    if(sStr.charAt(iJ)!=' ') break;

  return(sStr.substring(iI,iJ+1));
}

MEMBER FEEDBACK TO THIS TIP

The @DBLookup function for Web in the code at this line : vurl = trim(server)+trim(path)+view+"?readviewentries&count=10000"; we cannot have 10000 documents returned if in the server's document the maximum number of documents returned is for example 300. I Personnaly use this url it returns the maximum number of documents authortised by the server. vurl = trim(server)+trim(path)+view+"?readviewentries&count=-1"; (replace 10000 by -1).
—Zoubir A.

The problem with this approach is that the developer is creating an XML object for the entire view and then navigating through it. Not only is this inefficient but it could suck up a huge chunk of memory from the browser depending on the view size. What you should do is load a subset of view entries into the XML object instead of loading the entire view. This can be done by using the StartKey and UntilKey arguments of the ReadViewEntries call. I've included the help text from Domino explaining these arguments. StartKey = string Where: string is a key to a document in sorted view. The view displays at that document. In cases where there is no match for the StartKey, the next document is returned. So, for example, if the StartKey is "A" and there are no documents that begin with "A", StartKey returns the first document that begins with "B." UntilKey = string UntilKey is only valid when used with StartKey. It allows you to display the range of view entries beginning with the document specified by StartKey until the document specified by UntilKey. For example, &StartKey=A&UntilKey=B would give you all the entries that start with A. Use the &Count keyword to further limit the number of entries returned within any given range.
—Jerry B.

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

This tip was submitted to the SearchDomino.com tip library by member Wesley Guisso. Please let others know how useful it is via the rating scale below. Do you have a useful Lotus Notes, Domino, Workplace or WebSphere tip or code snippet to share? Submit it to our monthly tip contest and you could win a prize.

This was first published in January 2003

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.