PDA

View Full Version : What to use in place of @DbLookup in Domino database?



sandymonroe
29 Nov 2007, 1:53 PM
Again, I am not sure this is the place for this question since I am working with both Ext and Extnd and this question is specific to the implementation of Ext in Domino through Extnd... but I am also a member and have been told I should put my questions here. Please let me know if I am submitting my questions in the right place. Thanks!

I have been using a dblookup (and a dbColumn) javascript function from a script library that does not play nicely with Extnd and is therefore no longer being used in my apps. However these particular functions, as you know, are invaluable to what we do in Domino.

I am aware that EXTnd has the Forumla form but in my reading I haven't been able to find examples of how to use this, or if it is working yet. The last post specifically on that form said not to use it since it was not working. And in some cases I am in javascript when I need the information these functions would return, as below - I am working in the onload of the form, after the EXTnd form has loaded, before the user begins interacting with the form.

So... with that said, I need guidance.., help! Which direction should I be going, what should I be using to accomplish this?

Here is an example of how I use the script library functions and (below that) the original functions themselves (which are NOT compatible with EXTnd). Any help or quidance on how to accomplish this efficiently would really be appreciated. There are a lot of places where a lookup is done mid stream - very necessary for the apps we build.

Here are a couple of examples of how it is used in the code:
(above this is var doc = document.forms[0];)



if (isBeingEdited == "1") {

if (doc.status.value == "Inactive" && doc.userName.value == doc.Approver.value) {
//Get the number of allowable slots from ManagerSlotSettings view - brings back a text number
var allowedNum = dbLookup("", "", "ManagerSlotSettings", doc.Approver.value, 2);
//Get the number of active slots being used from ActiveSlots view which is totaled on 6th column - should return number of 1s in text string = "1, 1, 1"
var usedNum = dbLookup("", "", "ActiveSlots", doc.Approver.value, 5);
//This was changed on July 13th, 2007 - code was not working due to text values being returned by dblookups
if (usedNum == "" && eval(allowedNum) > 1) {
singleTag ('inline', 'ActivateButton_1');
}

var temp = new Array();
temp = usedNum.split(',');
if (temp.length == 1) {
var newNumber = parseInt(usedNum);
} else {
for (var t = 0; t < temp.length; t++) {
if (t==0) {
var newNumber = parseInt(temp[t]);
} else {
newNumber += parseInt(temp[t]);
}
}
}
if (newNumber <= allowedNum) {
singleTag ('inline', 'ActivateButton_1');
} else {
singleTag ('inline', 'ApproversInfo_1');

}
}


The 2 functions from the script library... (and the trim function they use)

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://servername"; // PUT YOUR SERVERNAME HERE http://11.22.33.44
server = "http://11.22.33.44";
} 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
server = "http://11.22.33.44";
} 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

jsakalos
30 Nov 2007, 1:18 AM
I'd be very glad if I could help you but I don't use Domino. If you don't get any response from others here I can move this thread to Notes/Domino Forum.

Jan K
3 Dec 2007, 11:51 PM
Hi.

I just came across this approach to doing DbLookups and DbColumns in JavaScript. Perhaps it can be helpful to you:

http://www.timtripcony.com/blog.nsf/d6plinks/GUIN-6SR4NR