Ask the Expert

Accessing location documents

How do you access the CURRENT location document from LotusScript? I am getting ready to decommission a mail server, and there is a group of users who no longer use Notes for email, but still use it to access applications. Since these users do not open the mailfile, I want to give them a stub database that they can be directed to in order to have their location document updated so that their Notes client does not try to check the non-existent server for mail.
This is one of those cases where it is handy that all parts of the Notes infrastructure share the same technology. The name of the current location is stored in the Notes.ini file and is available through the environment functions. The location documents are stored in the user's personal address book, which is an ordinary Notes database very similar in design to the public address book. The personal address book is nearly always "names.nsf" on the local machine, but the code below will find it no matter where it is. Since I have examined the design of the personal NAB in the past, I know just where to look to find the location documents.

This code will raise a user defined error 4101 if any problem occurs. If you don't catch it, the user will see it. To catch it, precede the call with an "ON ERROR 4101 goto MyHandler". In the handler, the error message can be accessed through $Error. You may want to collect error messages for analysis in a log or simply by emailing them somewhere. Due to the nature of this code, I'm reporting every error that could conceivably occur that I can think of.

Public Function GetCurrentLocation As NotesDocument

  • Dim session As New notessession
  • Dim books As Variant
  • books =session.AddressBooks
  • Forall b In books ' get users public address book
    • If Not b.IsPublicAddressBook Then
      • Call b.open("","")
      • If b.isOpen Then
        • Dim locations As NotesView
        • Set locations=b.GetView("Locations")
        • If Not locations Is Nothing Then
          • Dim key As String
          • key=session.GetEnvironmentString("Location",True)
          • If key<>"" Then
            • Dim index As Integer
            • index=Instr(key,",")
            • If index>0 Then key=Left(key,index-1)
            • Dim location As NotesDocument
            • Set location=locations.GetDocumentByKey(key,True)
            • If Not location Is Nothing Then
              • Set GetCurrentLocation=location
              • Exit Function
            • Else
              • Error 4101, {Current location document not found.}
            • End If
          • Else
            • Error 4101, {Unable to look up current location.}
        • End If
      • Else
        • Error 4101, {Personal name & address book does not contain a "Locations" view.}
      • End If
    • Else
      • Error 4101, "Unable to open personal name & address book"
    • End If
  • End If
  • End Forall
  • Error 4101, "Unable to locate personal name & address book"
    • End Function

    This was first published in September 2006

    There are Comments. Add yours.

     
    TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

    REGISTER or login:

    Forgot Password?
    By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
    Sort by: OldestNewest

    Forgot Password?

    No problem! Submit your e-mail address below. We'll send you an email containing your password.

    Your password has been sent to: