Tuesday, 11 January 2005

Javascript version of @DbLookup & @DbColumn

This is my award winning tip. Its used to perform @DbLookup & @DbColumn using Javascript on the browser without refreshing or reloading the page.

function dbLookup(server,path,view,key,column){

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

var pos=0;
currURL = (document.location.href).toLowerCase();
if (trim(server) == "") {
pos = currURL.indexOf('://');
if (pos < 0 )
server = "http://11.22.33.44" // PUT YOUR SERVERNAME HERE
else
{
pos += 3;
pos = currURL.indexOf('/', pos);
server = currURL.substring(0, pos)
}
}

if( trim(path) == "" )
{
if( pos > 0 )
{
newPos = currURL.indexOf('.nsf',pos);
if (newPos > 0)
{
path = currURL.substring(pos+1,newPos+4)
}
}
}

//Javascript index starts at 0, so need to decrement the column by -1
if( !isNaN(column) )
column -= 1;

vurl = trim(server)+"/"+trim(path)+"/"+view+"?readviewentries&login=1&count=9999&startkey="+key;
xmlDoc.load(vurl);
if (xmlDoc.documentElement == undefined)
{
return("")
}
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==key)
{
temp[j] = nodes.item(i).childNodes.item(column).text;
j++;
}
else
{
break;
}
}

var results = ""
for (var i = 0; i < j; i++)
{
if (i==0)
{
results = temp[i];
}
else
{
results = results + ", " + temp[i];
}
}

return(results);
} //End of dbLookup


function dbColumn(server,path,view,column){

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

var pos=0;
currURL = (document.location.href).toLowerCase();
if (trim(server) == "") {
pos = currURL.indexOf('://');
if (pos < 0 )
server = "http://11.22.33.44" // PUT YOUR SERVERNAME HERE
else
{
pos += 3;
pos = currURL.indexOf('/', pos);
server = currURL.substring(0, pos)
}
}

if( trim(path) == "" )
{
if( pos > 0 )
{
newPos = currURL.indexOf('.nsf',pos);
if (newPos > 0)
{
path = currURL.substring(pos+1,newPos+4)
}
}
}

if( !isNaN(column) )
column -= 1;

vurl = trim(server)+"/"+trim(path)+"/"+view+"?readviewentries&login=1&count=9999";
xmlDoc.load(vurl);

nodes = xmlDoc.documentElement.childNodes;
temp = new Array(nodes.length);
var j = 0;
for (var i = 0; i < nodes.length; i++)
{
temp[j] = nodes.item(i).childNodes.item(column).text;
j++;
}

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

return(results);
} //End of dbColumn

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));
} //End of trim


NOTE:
1) View should NOT be Categorized
2) works fine on IE 5.5 and above
3) "Server" and "Path" parameters are optional when used in current database

Usage Example:
1) Current Database
var a = dbColumn("","","Keywords",1)
var a = dbLookup("","","Keywords","LotusNotes",2)

2) Across Database
var a = dbColumn("http://11.22.33.44","folder/db.nsf","Keywords",1)
var a = dbLookup("http://11.22.33.44","folder/db.nsf","Keywords","LotusNotes",2)

01:55 Posted in Blog, Tips | Permalink | Comments (8) | Tags: Just talk Lotus

Comments

Wow - cool! I'm going to give it a try out tonight. Just on the surface, I'd say it was deserving of the award.

Cheers!

Jerry

Posted by: Jerry Carter | Wednesday, 19 January 2005

Sure ... i would be happy to know it works .. lol
let me know your thoughts.

Thanks Jerry.

Posted by: Ashish | Wednesday, 19 January 2005

url=http://portable-washer-and-dryers.beeplog.com]portable washer and dryers[/url] portable washer and dryers wet saw blades [url=http://wet-saw-blades.beeplog.com]wet saw blades[/url] steam shower [url=http://steam-shower.beeplog.com/]steam shower[/url] portable-washer-and-dryers.beeplog.com steam-shower.beeplog.com wet-saw-blades.beeplog.com

Posted by: Magdu | Saturday, 08 July 2006

crohns
hooka
greenies
[url=http://crohns.coz.in/]crohns[/url]
[url=http://hooka.coz.in/]hooka[/url]
[url=http://greenies.coz.in/]greenies[/url]

Posted by: Tim | Sunday, 09 July 2006

This one is not working..I dont know wats wrong...

Posted by: John Cruz | Thursday, 07 August 2008

hi there,

when i first tried the code it didn't work due to this line: vurl = trim(server)+"/"+trim(path)+"/"+view+"?readviewentries&login=1&count=9999&startkey="+key;

it's working great after i removed "login=1".

i looked up on designer 8's help and there's no mention bout the parameter 'login' when it comes to readviewentries.

what is the purpose of 'login'? mind sharing your thoughts?

and oh, this is a cool piece of code. thanks for sharing.

Posted by: yoges | Tuesday, 11 August 2009

The release of that version of Javascript is not well known in my town yet, but I'm using the same version, I'm studying for programming but the complexity is still something I can't manage.

Posted by: Viagra Online Without prescription | Tuesday, 03 August 2010

Sympa ici !

:)

Posted by: zombie flash game | Tuesday, 26 June 2012

Post a comment