API
@-Formulas
JavaScript
LotusScript
Reg Exp
Web Design
Notes Client
XPages
 
Get Address Book
I was writing some code to do some message validation before a message was sent. I needed to find the groups in a cascaded address book. This means I needed to process all the known address books, which is pretty easy because the NotesSession object has an AddressBooks property that gives you all the address books. You can just do a ForAll loop against those and process the different directories as the example from the Notes Help shows:

   Dim session As New NotesSession
   Dim books As Variant
   books = session.AddressBooks
   ForAll b In books
      Call b.Open( "", "" )
      MessageBox( b.Title )
   End ForAll

The problem here is that the variable "b" is a Variant. Normally that's not an issue, but if you do a search (like I wanted to do), you get an error. The object must be a NotesDatabase object to use that method. In Java, it's pretty easy to cast the object to the right data type, but not so easy in LotusScript.

What I ended up doing was using my GetDatabase function to get a handle to the database as the right type, and then use that. Here's the enhanced example code:

   Dim session As New NotesSession
   Dim books As Variant
   Dim db As NotesDatabase
   books = session.AddressBooks
   ForAll b In books
      Call b.Open( "", "" )
      If b.Server = "" Then
         Set db = GetDatabase(session, b.FilePath)
      Else
         Set db = GetDatabase(session, b.Server & "!!" & b.FilePath)
      End If
      MessageBox( db.Title )
   End ForAll