Domino Directory Type Ahead

Update: 2009 Jan 22 - Added link to dirlookup.css.

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

6 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

Gravatar Image4. Posted at 5/28/2009 10:38:19 AM by Ritesh Dahiya

Thank you so much for the domino type-ahead.

It worked just great.

I have implemented the similar one for products, facilities etc. lookup also. And they work great

I would like to mention just one correction though:

the lookupURL: should be "dirLookup?OpenAgent&q=", or the one with extracting substring

Gravatar Image5. Posted at 6/3/2009 11:59:15 AM by Aaron Hardin

Do you know why it would show Page can't be displayed under the drop down in IE, and in Firefox it has bullets kind of like the CSS isn't linking?

Thanks!!!

Gravatar Image6. Posted at 7/17/2009 10:47:50 AM by Mark Polacheck

Tanny... I have implemented the Domino Type ahead (you have helped me with an issue in the past on this) but have a problem where the IFrame dropdown does not show any results (my debug alerts show results are gotten, they just dont show up except for the first value in the focused field). When I look at the CSS file you provide, it seems to be incomplete , i.e. I dont see a Results1 class for instance. Can you send me a working CSS file for this feature ? Here is a paste of what I have in that CSS file that I downloaded from your Blog

#dirLookup {

margin: 0;

padding: 0;

background: #fff;

border: 1px solid #acacac;

border-width: 0 1px 1px;

list-style: none;

}

#dirLookup li {

padding: 0 4px;

cursor: default;

}

#dirLookup span {

cursor: inherit;

}

#dirLookup li.odd { background: #f0f0f0; }

#dirLookup li.selected { background: #ccc; }

#dirLookup span.result2 { display: none; }

Add a comment

Discussion for this entry is now closed.