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
LVL 2
YoinkAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

HemanthaKumarCommented:
Here is the script that does that what you asked for

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 col As NotesDocumentCollection
      Dim phoneList()
      
      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
      count = 0      
     '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 col = view.GetAllDocumentsByKey( person, True)
                  Set doc = col.GetFirstDocument
                  While Not doc Is Nothing
                        Redim Preserve phoneList(count) As Variant
                        If doc.OfficePhoneNumber(0) <> "" Then
                              phoneList(count) = doc.OfficePhoneNumber(0)
                              count = count + 1
                        End If                        
                        done = True
                        Set doc = col.GetNextDocument(doc)
                  Wend
                  If done = False Then
                        Messagebox _
                        ( "Sorry, unable to locate person's name." )
                        Exit Sub
                  Elseif Ubound(phoneList)=0 Then
                        Call UIDoc.FieldSetText( "txtPhoneNumber", phoneList(0))
                  Elseif Ubound(phoneList)>1 Then
                        ret = ws.prompt( PROMPT_OKCANCELLIST, "TITLE", "Prompt", "", phoneList)
                        If Not Isempty(ret) Then
                              Call UIDoc.FieldSetText( "txtPhoneNumber", ret(0))
                        End If                        
                  End If
            End If
      End Forall
      
End Sub

~Hemanth
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
qwaleteeCommented:
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
0
HemanthaKumarCommented:
Did you meant this

 Set col = view.GetAllDocumentsByKey( person, True)
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

qwaleteeCommented:
HemanthaKumar,
> Did you meant this

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

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

0
qwaleteeCommented:
Sorry, must have scrolled back up to his code and confused it for yours.
0
YoinkAuthor Commented:
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.
0
qwaleteeCommented:
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Lotus IBM

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.