Home > Domino Tips > Developer > JavaScript > JavaScript Domino directory name validation
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

JAVASCRIPT

JavaScript Domino directory name validation


Dennis Potts
05.04.2005
Rating: -3.58- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


View member feedback to this tip.

This JavaScript will check if an exact match is found in the Domino Directory. If no match is found, an alert message will appear and return focus to the field.

The function takes four parameters, which are explained in the source code. The exact match in the Domino directory is case insensitive. The main goal is to make sure the name is able to be resolved in the Domino directory.

If you omit the myOrg argument to the isInNab function, the common name will be searched instead of the canonical name. However, the name will only be matched up to the number of characters you enter. A mail routing failure may occur if duplicate are names found. For my purposes, I am at least sending the organization to the function. Passing the organization will place distinct delimiters around the name to get the exact match. ("CN=" is the prefix and "O=/..." is the suffix)

Code

/*
Below is a JavaScript code snippet that 
may be added to the onBlur event 
of a text field to validate against the 
Domino directory.
*/

var myHost = window.location.protocol +
 "//" + window.location.host + "/names.nsf"; 
var myOrg = "Sandbox"; 
var alertmsg = "Name not found in Addressbook. 
Please try again."; isInNab( this, myHost, myOrg, alertmsg );


/*
Below is the code that may be added to the JSHeader of the form 
that contains the field that is being validated.
*/

// Checks a single public address book to 
confirm if a name is found.
/*
This function is intended for IE browsers 
that provide the Microsoft.XMLDOM

fld   = The web text field that contains the SendTo name.
nabDB = The URL that points to the Domino directory. 
Example: http://mydomain.com/names.nsf
myOrg  = The organization name used in the
 Domino hierarchy. If you pass an empty myOrg
                   value, the comman name will be 
searched in the ($Users) view if the Domino Directory.
                   You can also send an ORG/OU, ORG/OU/OU..., etc 
as an aurgument.
alertMsg = The message that appears to the 
user if the name is not found in the Domino Directory.                   
*/                  

function isInNab ( fld, nabDB, myOrg, alertMsg ) { 

 if ( ! alertMsg ) {
  alertMsg = "Name not found in public address book.";
 }
 
 myOrg = myOrg.toLowerCase();
 
 function loadXML(xmlFile ) {
   xmlDoc.async="false";
   xmlDoc.onreadystatechange=verify;
   xmlDoc.load(xmlFile);
   xmlObj=xmlDoc.documentElement;
 }
 
 function verify() {
   if (xmlDoc.readyState != 4)  {
     return false;
   }
 }
 
 // Note: The domain in nabDB is usually the 
same as the HTML page that calls the URL.
 //            IE may prompt you if you to execute 
a call to a foriegn domain or not run if you cross 
  //            domain boundaries between the 
caller and callee (pending browser security settings).
 
 var resourcePrefix = "/$users/?ReadViewEntries&startkey=cn=";
  var resourceSuffix = "";
 var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
 var person = fld.value.toLowerCase();

 resourceSuffix += "&count=1";  
 
 /*
 A user may use a dialog picker to get the name value.
In order to build a lookup based on 
common name or abbreviated name, 
we must make sure we start with a common name.
 
 Perform a loose @Name( [CN]... ) of the person value.
Change the lookFor array and Switch statement below 
to include other hierarchy transformations if needed.
 */

 var pos = 0;
 var cnt = 0; // Used to count when /org and o=org is transformed. 
                         // It will be determined invalid 
if a target exist after all transformations.
                         
 var lookFor = new Array( 2 ) 
 lookFor[ 0 ] = "/" + myOrg;
 lookFor[ 1 ] = "cn=";
 lookFor[ 2 ] = "/o=";

 for ( target = 0 ; target < 3 ; target++ ) {
  pos = person.indexOf( lookFor[ target ] );

  if ( pos != -1 ) {
  
   switch( target ) {
    case 0:
     person = person.substr( 0, pos );
     cnt++;
     break;

    case 1:
     if ( person.length >= pos + 3 ) {
      person = person.substr( pos + 3 );
     } 
     break;

    case 2:
     person = person.substr( 0, pos );
     cnt++;
     break;
   }  
  }   
 }
 
 loadXML( nabDB + resourcePrefix + 
person + resourceSuffix );
 var fullName = 
xmlDoc.getElementsByTagName('FullName');
 
 /* 
 Now we will append the "/o=myOrg" 
onto the end of person if myOrg was passed
 before we see if it is contained in the 
result from the Domino directory
 */
 if ( myOrg != "" ) {
  person += "/o=" + myOrg;
 }
 
  if ( ( fullName.context.text.toLowerCase() ).
indexOf( person ) == -1 || cnt == 2 ) {
    alert( alertMsg );
    fld.focus();
  }
}

MEMBER FEEDBACK TO THIS TIP

This tip is a variation a previously published tip, JavaScript version of @DBLookup and @DBColumn.

—Carlos Andres J.

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

This tip was submitted to the SearchDomino.com tip exchange by member Dennis Potts. 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 monthly tip contest and you could win a prize and a spot in our Hall of Fame.

Rate this Tip
To rate tips, you must be a member of SearchDomino.com.
Register now to start rating these tips. Log in if you are already a member.


Submit a Tip




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


RELATED CONTENT
JavaScript
Prevent errors on iFramed pages with JavaScript
How to add keyboard functionality for Lotus Notes documents
Validate Lotus Notes Domino fields using JavaScript
How to support Flash objects in any Web browser for a Lotus Notes Domino application
How to validate Lotus Notes forms on a Domino server without losing entered data
Ajax code equivalent of the @DBColumn formula for Lotus Notes
A bevy of Notes/Domino development tips
Loading XML from JavaScript
Delimiting the main code in JScript.NET
Remove commas from dollar amounts in JavaScript using a split

JavaScript for Lotus Notes Domino
Mimic Lotus Notes Domino application functionality on the Web
Prevent errors on iFramed pages with JavaScript
Top 10 Lotus Notes Domino programming and development tips of 2007
How to add keyboard functionality for Lotus Notes documents
Validate Lotus Notes Domino fields using JavaScript
How to support Flash objects in any Web browser for a Lotus Notes Domino application
How to validate Lotus Notes forms on a Domino server without losing entered data
A bevy of Notes/Domino development tips
Loading XML from JavaScript
Top 10 Notes/Domino developer tips of 2006

Lotus Domino Directory
Find a Lotus Notes user within NAB Deny Access groups
Troubleshoot Lotus Notes Out of Office (OOO) agent error messages
Create a computed Lotus Notes field to list Personal Address Book names
Domino Directory management tips and tutorials
How to correct Lotus Notes public key mismatches in four easy steps
How to automatically create a backup copy of your Domino Directory
Get all members of Domino Directory Group
"NAB" your Domino directory problems before they spread
Person document lost from the Domino Directory
Adding a sendmail e-mail list to Domino directory

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.

HomeNewsTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 1999 - 2008, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts