NotesDirectory + NotesDirectoryNavigator: Querying the Domino Directory from LotusScript
Your agent needs to look up a user’s mail server, check group membership, or verify that a Notes name exists. The instinct is db.GetView("($Users)") and scan — but that means opening names.nsf manually, managing view caching, and accounting for multiple directory sources (primary + extended + LDAP).
LotusScript’s NotesDirectory handles all that transparently. It’s a high-level directory query API available since Notes 7 — the server may have one directory or ten, and this class abstracts the structure away.
TL;DR
NotesDirectoryis the high-level directory query API — no need to open names.nsf yourself- Entry point:
session.GetDirectory(serverName)— empty string""means local LookupNames(view, names, items)— specify a view, a batch of names, and which fields to fetch; results are cached in the objectLookupAllNames— scans every name in a viewGetMailInfo(name)— retrieves mail server and mail file path for a user in one call- Walk results with
NotesDirectoryNavigator—FindFirstName/FindNextName/GetFirstItemValue LimitMatches = Truecaps results at 50 (performance guard);SearchAllDirectories = Truesearches all configured directories
Getting a NotesDirectory object
Dim session As New NotesSession
' Query the local server's directoryDim dir As NotesDirectorySet dir = session.GetDirectory("")
' Query a specific server's directorySet dir = session.GetDirectory("MailServer/ACME")
Print "Directory server: " & dir.ServerLookupNames — fetch specific fields for named entries
' Look up FullName, MailServer, MailFile for two peopleDim names(1) As Stringnames(0) = "John Smith"names(1) = "Alice Chen"
Dim items(2) As Stringitems(0) = "FullName"items(1) = "MailServer"items(2) = "MailFile"
' LookupNames caches the results in the dir objectCall dir.LookupNames("($Users)", names, items)
' Build a navigator to walk the resultsDim nav As NotesDirectoryNavigatorSet nav = dir.CreateNavigator()
If nav.FindFirstName() Then Do Print "Name: " & nav.GetFirstItemValue() If nav.FindFirstItem("MailServer") Then Print "Mail server: " & nav.GetFirstItemValue() End If If nav.FindFirstItem("MailFile") Then Print "Mail file: " & nav.GetFirstItemValue() End If Loop While nav.FindNextName()End IfGetMailInfo — fast mail routing lookup
Instead of a manual LookupNames, GetMailInfo retrieves a user’s mail configuration in one call:
Dim mailInfo As VariantmailInfo = dir.GetMailInfo("John Smith")
' mailInfo(0) = MailServer (e.g. "MailServer/ACME")' mailInfo(1) = MailFile (e.g. "mail/jsmith.nsf")' mailInfo(2) = MailDomain' mailInfo(3) = MailSystem (constant: MAIL_NOTES_TYPE = 1)
If Not IsNull(mailInfo) Then Print "Mail server: " & mailInfo(0) Print "Mail file: " & mailInfo(1)End IfThis is the most practical method in day-to-day use — any time you need to open a user’s mail.nsf, auto-forward, or look up routing info, GetMailInfo saves the manual lookup.
LookupAllNames — scan a whole view
Dim items(0) As Stringitems(0) = "FullName"
' Scan every entry in $UsersCall dir.LookupAllNames("($Users)", items)
Dim nav As NotesDirectoryNavigatorSet nav = dir.CreateNavigator()
Dim count As Integercount = 0If nav.FindFirstName() Then Do count = count + 1 Loop While nav.FindNextName()End IfPrint "Directory has " & count & " users"Note: when LimitMatches = True, only the first 50 results are returned. Set dir.LimitMatches = False before a full scan, but be aware of the performance cost on large directories.
Walking results with NotesDirectoryNavigator
NotesDirectoryNavigator is the cursor for walking the cached LookupNames results:
| Method | Description |
|---|---|
FindFirstName() | Move to the first name (resets position) |
FindNextName() | Move to the next name |
FindFirstItem(itemName) | Under the current name, move to a named item |
FindNextItem() | Move to the next occurrence of the same item (multi-value fields) |
GetFirstItemValue() | Return the current item’s first value |
GetNextItemValue() | Return the next value of the current item |
Two key properties
' Search all configured directories (primary + extended + LDAP)dir.SearchAllDirectories = True
' Cap LookupNames results at 50 per call (default True)' Set to False for full scans — but watch the performance impactdir.LimitMatches = FalseSearchAllDirectories = False (default) queries only the primary Domino Directory — faster. True includes all configured auxiliary directories.
What about Java and SSJS?
| Language | Counterpart |
|---|---|
| LotusScript | NotesDirectory / NotesDirectoryNavigator |
| Java | lotus.domino.Directory / DirectoryNavigator (drop the Notes prefix; .recycle() when done) |
| SSJS | No direct equivalent — directory lookups in XPages are typically done via the Domino REST API |