Solved

Look up the phone number in the e-mail directory

Posted on 2003-12-04
10
272 Views
Last Modified: 2013-12-18
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
0
Comment
Question by:Yoink
  • 4
  • 3
10 Comments
 
LVL 24

Accepted Solution

by:
HemanthaKumar earned 125 total points
ID: 9874910
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
 
LVL 31

Expert Comment

by:qwaletee
ID: 9879246
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
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 9882514
Did you meant this

 Set col = view.GetAllDocumentsByKey( person, True)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 31

Expert Comment

by:qwaletee
ID: 9882928
HemanthaKumar,
> Did you meant this

>  Set col = view.GetAllDocumentsByKey( person, True)
Exactly!
0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 9883567
Then the script above provided by me does have that..check your comment

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

0
 
LVL 31

Expert Comment

by:qwaletee
ID: 9884437
Sorry, must have scrolled back up to his code and confused it for yours.
0
 
LVL 2

Author Comment

by:Yoink
ID: 9896603
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
 
LVL 31

Expert Comment

by:qwaletee
ID: 9897039
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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Email relaying to outside address 4 178
Domino Lotus Notes Client 4 73
Lotus notes - Follow up notes mail missing 15 80
Lotus notes Formula to trigger Lotusscript 1 1,071
Lack of Storage capacity is a common problem that exists in every field of life. Here we are taking the case of Lotus Notes Emails, as we all know that we are totally depend on e-communication i.e. Emails. This article is fully dedicated to resolvin…
This article covers general Notes 8.5 troubleshooting information including recreating the Notes\Data folder.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question