Manage Learn to apply best practices and optimize your operations.

@DBLookup function for Web

Learn how to simulate the @DBLookup function in a Web browser to return a Lotus Notes Domino array using some JavaScript code.

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
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.

Dig Deeper on Lotus Notes Domino Administration Tools

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

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 ...

SearchDataCenter

SearchContentManagement

Close