Domino Directory Type Ahead

Around December 2006 I read a tip on Julian Robichaux's site about Google Suggest-type Lookups In Notes code he had written. I downloaded the code and thought that I could make a few improvements. I changed the code to:

  • Use Object Literal Notation.
  • Added highlighting/auto complete support.
  • Changed to code to dynamically create script elements for data instead of using the XML HTTP request object. Using script files gets rid of cross domain scripting security issues.
  • Supports multiple input fields instead of one field.
  • Supports the ($VIMPeopleAndGroups), ($VIMGroups) and ("Servers") views in addition to the ($VIMPeople) view.

dirlookup.gif

I'm sorry it's taken a year and a half to publish.

Syntax:

dirLookup.init(element, viewType, addressType, callback);

Parameters

viewType

Numeric. Optional. 1 - (default) People only, 2 - People and groups, 3 - groups only, 5 - servers.

addressType

Numeric. Optional. 1 - (default) set field to the Notes address, 2- set field to the internet address.

callback

Function. Optional. Called when user leaves the input field. Can be used to get other information with AJAX calls.

Usage

Include the following lines in the head section of your Domino web page.

<link type="text/css" media="screen" rel="stylesheet" href="css/dirlookup.css">
<script type="text/javascript" src="js/events.js"></script>
<script type="text/javascript" src="js/dirlookup.js"></script>

For each <input> element you want to add directory lookup functionality add an onfocus event calling dirLookup.init(). Here's what I used for the sample.

<script type="text/javascript">
// Initialization functions
addEvent(window, "DOMContentLoaded", function(e) {
	// Lookup by people and groups, returning the Notes name.
	addEvent(document.getElementById("NameLookup"), "focus", function() { dirLookup.init(this,2); });

	// Lookup by people only, returning the Notes name.
	addEvent(document.getElementById("pNameLookup"), "focus", function() { dirLookup.init(this); });

	// Lookup by people and groups, returning the internet address.
	addEvent(document.getElementById("igNameLookup"), "focus", function() { dirLookup.init(this,2, 2); });

	// Lookup by people only, returning the internet address.
	addEvent(document.getElementById("iNameLookup"), "focus", function() { dirLookup.init(this,1,2); });

	// Set focus to the first lookup field.
	document.getElementById("NameLookup").focus();
});
</script>

Check out the sample.

Samples and Download

Monday, May 26th, 2008 07:59:51 PM in  Web Development 

3 Comments

Gravatar Image1. Posted at 9/17/2008 6:24:00 PM by Ali

Hello Tanny

Thank you for posting Domino type-a-head directory lookup. I have read your instructions and tried to use your updated script in the Domino form calling dirlookup.init from field focus event and also placing call to dirLookup.js and events.js in the HTMHead of the form and created a script library for websession. It didn't work. Then I created a notes agent from dirLookup.jss and called the agent from onFocus event of the field in the Domino form. Still did work. Can these type-a-head programs be used

with Domino form?

Thank you,

Ali

Gravatar Image2. Posted at 9/18/2008 1:39:03 AM by Tanny O'Haley

Hi Ali,

I have used this code on Domino forms, .NET and HTML pages. I did notice that my instructions don't tell you how to create the agent and the modifications you must make for a Domino Web Form in your environment.

Create the WebSession Script Library

  1. From the Script Libraries view in Domino Designer, click the New LotusScript Library button.
  2. Delete the contents of the library.
  3. Paste the contents of the WebSession.lss file into the script library.
  4. Save the script library as WebSession.

Create the LookupDir Agent

  1. From the Agents view in Domino Designer, click the New Agent button.
  2. Enter LookupDir in the Name field.
  3. Click the On schedule trigger.
  4. Select Never from the Schedule dropdown.
  5. Select LotusScript for the agent language.
  6. Paste the contents of the dirlookup.lss file into the LookupDir agent.
  7. Change the domain constant from nospam.com to your domain.
  8. Save the agent.

Depending on the location of the form you will have to change the lookupURL variable in the dirlookup.js file to point to the agent. For Domino Web Forms, I have it changed it from:

lookupURL: "LookupDir?OpenAgent&q=",

to:

lookupURL: location.href.substr(0, location.href.toLowerCase().indexOf(".nsf/") + 5) + "LookupDir?OpenAgent&q=",

This makes sure that the variable always points to the agent, no matter what the format of the URL. If the URL is http://yourdomain.com/apps/test.nsf/testform?Open or http://yourdomain.com/apps/test.nsf/viewUNID/documentUNID?EditDocument the dirlookup.js file will always have the correct URL to the LookupDir agent.

If it still doesn't work for you, please send me a link to your form.

Tanny

Gravatar Image3. Posted at 9/19/2008 6:35:24 PM by Ali

Hi Tanny,

I followed your instructions I was able to see that the field pulls the data from notes view but there was another page that showed page can not be displayed was displaying on the top of the names in the dropdown list I checked DirLookup.js file. There is a function called adjustIFrame. I commented out the following line: newNode.src='//0';

Now is displaying but dropdown list display twice such as alik@www.comalik@www.com but when I select one it display just one name. Before I change the line I tested on FireFox browser it workd fine. Even displayed highlights for dropdown list. But using IE the entries indent and fall off the box. I am writing to let you know. I will work on it to find out why. If I find the cause I will posted here too. Thank you

Ali

Add a comment

Comment Preview

Comment Guidlines

Keep comments relevant. Inappropriate, offensive or off topic comments may be edited and/or deleted. Advertisements will be deleted.

If you choose to comment, please leave a real name, not an alias, and an email address or a link to your own site.

E-mail addresses will not be displayed. If you leave an e-mail address and I respond to your comment you will receive the response at your e-mail address.