Tuesday, July 3, 2018

Verify the addresses in a field are in the Lotus Addressbook


While I am not a fan of it, you sometimes have to create an application internal group for notifications.  In Domino, the admin-p process takes care of keeping your groups maintained when someone leaves or has a name change.  But what about those internal groups?  They aren't maintained by the system.  And most of the time, your application administrators (typically end users) are more focused on adding names.  So how do you keep the list clean?

To solve this issue, I wrote the below code and added it to the "Exiting" subroutine of a field.  It will basically read through every entry of the field and verify that the address exists in the public address book (NAB).  If it doesn't find the address, it's removed from the field.  This has worked well in keeping old addresses out of our fields.

The better solution would be to have a group in your address book.  But when you can't do that, this will help keep your lists clean.


Sub Exiting(Source As Field)
%REM
Validate the members of this group exist in the NAB
Created by David
%END REM

Dim s As New notessession
Dim uiw As New notesuiworkspace
Dim doc As Notesdocument
Dim x As Integer
Dim j As Integer
Dim listIn As Variant
Dim listOut As Variant

Dim db As NotesDatabase
Dim ses As New NotesSession
Dim ndoc As NotesDocument
Dim view As NotesView
Dim vc As NotesViewEntryCollection

    'Let's initially open this DB and then connect to a view
Set db = New NotesDatabase("server-name","names.nsf")
Set view = db.GetView( "($Users)" )
Set vc = view.AllEntries

Set  uidoc = uiw.currentdocument
Set doc = uidoc.document
listIn = doc.GetItemValue("Field-Name")
Redim listOut(Ubound(listIn)) As Variant

j = 0
For x = 0 To Ubound(listIn)
Set ndoc = view.GetDocumentByKey(listIn(x),True)
If Not (ndoc Is Nothing) Then
listOut(j) = listIn(x)
j = j + 1
End If
Next

Call doc.ReplaceItemValue("Field-Name", listOut)
Call uidoc.Reload
End Sub