Solved

Look up the phone number in the e-mail directory

Posted on 2003-12-04
10
269 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
Comment Utility
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
Comment Utility
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
Comment Utility
Did you meant this

 Set col = view.GetAllDocumentsByKey( person, True)
0
 
LVL 31

Expert Comment

by:qwaletee
Comment Utility
HemanthaKumar,
> Did you meant this
>
>  Set col = view.GetAllDocumentsByKey( person, True)
Exactly!
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 24

Expert Comment

by:HemanthaKumar
Comment Utility
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
Comment Utility
Sorry, must have scrolled back up to his code and confused it for yours.
0
 
LVL 2

Author Comment

by:Yoink
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
IBM Notes offer Encryption feature using which the user can secure its NSF emails or entire database easily. In this section we will discuss about the process to Encrypt Incoming and Outgoing Mails in depth.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now