Link to home
Start Free TrialLog in
Avatar of Yoink
Yoink

asked on

Look up the phone number in the e-mail directory

I am new to programming in Notes, and I am stuck on how to look up a phone number in the e-mail directory.

I found some code in the Help menu that will return the phone number for a user in the e-mail directory (I modified it a bit):

Sub GetPhoneNumber
      Dim session As New NotesSession
      Dim books As Variant
      Dim view As NotesView
      Dim doc As NotesDocument
      Dim done As Variant
      Dim person As String      
      
      Dim ws As New NotesUIWorkspace
      Dim UIDoc As NotesUIdocument
      Dim db As NotesDatabase
      Dim strDebug As String
      Dim strPhoneNumber As String
      Dim choose As String
      
      Set db=session.currentdatabase
      Set UIdoc = ws.currentdocument
      
      Call UIDoc.save
      
      books = session.AddressBooks
      done = False
      
      'textValue$ = notesUIDocument.FieldGetText( [ fieldName$ ] )
      person=UIDoc.FieldGetText( "txtTest" )
      'person=UIDoc.FieldGetText( "txtPhoneName" )
      ' ( "Enter the last name of the person: ", "Last name" )
      Forall b In books
    ' check every Domino Directory,
    ' unless we're already done
            If ( b.IsPublicAddressBook ) And ( Not done ) Then
                  Call b.Open( "", "" )
      ' look up person's last name
      ' in People view of address book
                  Set view = b.GetView( "People" )
                  Set doc = view.GetDocumentByKey( person )
      ' if person is found, display the phone number item
      ' from the Person document
                  If Not ( doc Is Nothing ) Then
                        'Messagebox( "Phone for " + person  _
                  '      + " is " + doc.OfficePhoneNumber(0 ) )
                        done = True
                        strPhoneNumber=doc.OfficePhoneNumber(0)
                        Call UIDoc.FieldSetText( "txtPhoneNumber", strPhoneNumber$)      
                  End If
            End If
      End Forall
  ' if done is still False, the person wasn't found
      If Not done Then
            Messagebox _
            ( "Sorry, unable to locate person's name." )
      End If
End Sub

The problem is this function will return the first name it finds.  There are several cases where there are duplicate names in the "People" view.  The unique identifier in this case is e-mail address.  How can I modifiy my code to have a dialog box appear with all of the potential values returned by the function, then allow the user to select one of these values in order to return the phone number?

Thanks in advance,

krameje
ASKER CERTIFIED SOLUTION
Avatar of HemanthaKumar
HemanthaKumar

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of qwaletee
qwaletee

Note that both of the above will retrun "partial matches."  For example, if you have two users to look up:
Michael Johns
Michael Johnson

If both are in the directory, then yuo will get correct results for each, as exact matches take precedence over inexact matches.

Bt, if only Michael Johnson is listed, then BOTH searches will return only Michael Johnson's number!

To fix that, you need to add the exactMatch parameter to getDocumentByKey or getAllDocumentsyKey
Did you meant this

 Set col = view.GetAllDocumentsByKey( person, True)
HemanthaKumar,
> Did you meant this

>  Set col = view.GetAllDocumentsByKey( person, True)
Exactly!
Then the script above provided by me does have that..check your comment

>Note that both of the above will retrun "partial matches."

Sorry, must have scrolled back up to his code and confused it for yours.
Avatar of Yoink

ASKER

Thank you both for your suggestions.  I am not having an issue matching name.  The issue is when there are two separate e-mail addresses in the directory with same name in the person column.  For example:  John_Smith@something.com and John_A_Smith@something.com may appear in the e-mail directory as Smith , John.  What I am looking for is a way to have a dialog box appear showing both of these entries, and have the user select the entry he/she wishes to view.
Wait, I'm confused.  It sounds like you are asking for exactly what Hemantha provided you.  It finds all matching entries from the People view.  If a list (more than one) comes back, it displays a dialog box showing all the choices.

There are only two possible things I can see that you might want changed:

1) If it is hard to differentiate between the two entries, you may want to be able to allow the user to display the full Person document, similar to the way the Address Dialog allows you to show the full document; this involves a major code change

2) As an alternative, you may want the dialog list to simply display more info about the person, which involves a minor change (gather more information for each entry in the array in the WHILE loop, and pick off only the phone number from that info once user makes a choice)

3) The lookup key may not work for you, r may not be optimal, in which case you need to create a new view with the correct key column.