Manage Learn to apply best practices and optimize your operations.

Using Ajax as a replacement for @DBLookups

In this tip, a developer explains how he started using AJAX for @DBLookup functions.

We have started implementing Ajax (Asynchronous JavaScript and XML) in a number of applications at my company. Most of what we have done has been using agents to bring back HTML to change a Web page using

VIEW MEMBER FEEDBACK TO THIS TIP

the .innerHTML property. But I was thinking that I could just as easily bring back the same information I can get in an @DBLookup. The approach I took is very specialized, but can be expanded to pull back any information you would ever want.

Basically, I have a contact name field and a contact phone number field on the form in question. I want the contact phone field to be automatically populated from data in the person document. So I have the onBlur event for the contact name field set to getContactPhone(document.forms[0].contact.value,'contact_phone'); so that the contact's phone number is looked up in the Public Address Book whenever the user tabs out of the field.

The agent I created, GetOfficePhone, returns the user's phone number I want with two print statements:

Print "Content-type: text/plain"
Print doc.OfficePhoneNumber(0)

This technique could definitely be expanded to do full blown @DbColumn and @DBLookup functions. The JavaScript is as follows:

var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
xmlhttp = new ActiveXObject
("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject
("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
@end @*/

if (!xmlhttp && typeof XMLHttpRequest != 
'undefined') {
  xmlhttp = new XMLHttpRequest();
}

function getContactPhone(username, objID) {
  var obj = document.getElementById(objID);
  xmlhttp.open("GET", 
"/names.nsf/GetOfficePhone?
OpenAgent&username=" 
+ username);
  xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 
4 && xmlhttp.status == 200) {
      obj.value = xmlhttp.responseText;
    }
  }
  xmlhttp.send(null);
}

You can e-mail me with any questions.

MEMBER FEEDBACK TO THIS TIP

I wanted to point out that this kind of functionality has been around for years -- I've personally been using the XML parser together with agents, and ?ReadViewEntries to get back results on the fly since 2002. It's amusing that only now when someone gives it a fancy name (AJAX) that everyone suddenly jumps on the bandwagon and claims they only just thought up how to do this. Articles like this have been around on the Internet for a while, including SearchDomino.com if I remember rightly.

It might be interesting to do a survey of your users to see just how many users were already aware of technology like this before some bright spark came up with the idea of naming the technology!

—Giles H.

******************************************

Good tip. However, the code is almost verbatim from another site: http://jibbering.com/2002/4/httprequest.html.

—Julian M.

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

This tip was submitted to the SearchDomino.com tip exchange by member Sean Burgess. 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 last published in August 2005

Dig Deeper on Ajax for Lotus Notes Domino

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

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

SearchEnterpriseLinux

SearchDataCenter

SearchExchange

SearchContentManagement

Close