Example – get info from current location document:
Dim l As New LocationDocument("")
Msgbox l.EmailAddress
Example – get info from named location document:
Dim l As New LocationDocument("Office")
Msgbox l.EmailAddress
Code:
'/**
' * LotusScript class for interacting with location documents
' * in the personal name and address book.
' */
Public Class LocationDocument
'declarations
Private pSession As NotesSession
Private pDb As NotesDatabase
Private pDoc As NotesDocument
'/**
' * Constructor
' */
Public Sub New(get_location As String)
'declarations
Dim viewNab As NotesView
Dim nn As NotesName
Dim ini_location As String
Dim location As String
Dim comma As Integer
'get session
Set Me.pSession = New NotesSession()
If get_location = "" Then
'get the location from notes.ini
ini_location = Me.pSession.GetEnvironmentString("Location", True)
'parse out the location name if none specifed in the constructor
comma = Instr(1, ini_location, ",")
location = Mid$(ini_location, 1, comma-1)
Else
'use supplied location name
location = get_location
End If
'abbreviate the name
Set nn = New NotesName(location)
location = nn.Abbreviated
'get database and view
Set Me.pDb = Me.pSession.GetDatabase("", "names.nsf")
Set viewNab = Me.pDb.GetView("Locations")
'lookup location document
Set Me.pDoc = viewNab.GetDocumentByKey(location, True)
If Me.pDoc Is Nothing Then
Error 9999, "Location document not found in names.nsf"
End If
End Sub
'/**
' * Saves.
' */
Public Sub Save()
Call Me.pDoc.Save(False, False)
End Sub
'/**
' * Property to get the backend document.
' */
Public Property Get Document As NotesDocument
Set Document = Me.pDoc
End Property
'/**
' * Property to get the e-mail address.
' */
Public Property Get EmailAddress As String
EmailAddress = Me.pDoc.GetItemValue("ImailAddress")(0)
End Property
'/**
' * Returns the name of the directory server.
' */
Public Property Get DirectoryServer As NotesName
Dim nn As New NotesName(Me.pDoc.GetItemValue("DirectoryServer")(0))
Set DirectoryServer = nn
End Property
'/**
' * Sets the name of the directory server.
' */
Public Property Set DirectoryServer As NotesName
Call Me.pDoc.ReplaceItemValue("DirectoryServer", DirectoryServer.Canonical)
End Property
'/**
' * Returns the name of the Sametime server.
' */
Public Property Get SametimeServer As NotesName
Set SametimeServer = New NotesName(Me.pDoc.GetItemValue("SametimeServer")(0))
End Property
'/**
' * Sets the name of the Sametime server.
' */
Public Property Set SametimeServer As NotesName
Call Me.pDoc.ReplaceItemValue("SametimeServer", SametimeServer.Canonical)
End Property
End Class