Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Lookup Email from NAB using first name and last name ONLY!

Posted on 2010-11-22
4
Medium Priority
?
795 Views
Last Modified: 2013-12-18
Following on from http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/Lotus_SmartSuite/Lotus_Notes/Q_26622828.html

Large company, plenty of duplicate First/Last names, haven't even looked at how they resolve that, either with different OU's or using middle names.

I have a field with first name and last name e.g. "Robert Smith", I need to lookup their email address from the NAB. There may or maybe not be multiple Robert Smith's. If there is only one, then I just want to populate the email field on my form with their email address. If there are multiple entries, I want a dialogue box to appear showing ONLY the people with that last name, so that the user can select the correct one from the list.

I am using LotusScript for this.
0
Comment
Question by:Sam654
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 5

Assisted Solution

by:RonaldZaal
RonaldZaal earned 700 total points
ID: 34194476
Hello,  you can try with this:

Dim adress As String
Dim sFormula As String
Dim eMail As Variant
dim thename as string

thename = "Smith"
sFormula = {@NameLookup([NoUpdate];"}+thename+{";"InternetAddress")}    ' formula to return emailaddress (es) from NAB
eMail = Evaluate(sFormula) ' returns array with 0,1 or multiple names
Msgbox eMail(0)   ' to test to return the first one found
0
 
LVL 5

Expert Comment

by:RonaldZaal
ID: 34194512
and then you check the returning eMail array for number of values returned by the formula with a test on the Ubound value.

if ubound(eMail) = 0 then
msgbox "no name found!"
end
end if

if ubound(eMail) > 1 then .....
dialogbox to let the user choose one name from the arr eMail
else
msgbox eMail(0)   ' got only on name
end if
0
 
LVL 22

Expert Comment

by:mbonaci
ID: 34194848
Modification of the function I mentioned in the previous thread to get all documents by user name:
Function getAllUserDocumentsFromNAB( UserCommonName As String ) As NotesDocumentCollection
        'Mb¤, 23.11.2010
        'The function returns all user documents from server's NAB
        Dim s As New NotesSession
        Dim nab As NotesDatabase
        Dim v As NotesView

        'if you're running this locally change the first (server) param
        'or you can use notesDatabaseArray = notesSession.AddressBooks
        Set nab = s.GetDatabase( s.CurrentDatabase.Server, "NAMES.NSF", False)
        If Nab Is Nothing Then Exit Function
        
        Set v = nab.GetView("($Users)")
        If v Is Nothing Then Exit Function
        
        Set getAllUserDocumentsFromNAB = v.GetAllDocumentsByKey( s.CommonUserName, True )
        
End Function

Open in new window


How to use the function in your case (i wrote it here so expect errors):
        Dim w As New NotesUIWorkspace
        Dim c As NotesDocumentCollection
        Dim cur As NotesDocument
        Dim lstUsers List As NotesDocument
        Dim arrUsers() As String
        Dim commonName As String
        Dim i As Integer
        Dim response As Variant
        
        commonName = "common username" 'you get this from somewhere...

        Set c = getAllUserDocumentsFromNAB(  )
        If c.Count = 0 Then Exit Sub 'or handle this case differently

        Set cur = c.GetFirstDocument

        If c.Count > 1 Then 'there's more than one - prompt the user to choose
                Redim arrUsers( c.Count - 1 )
                Do Until cur Is Nothing

                        'collect the values for dialog
                        arrUsers( i ) = cur.InternetAddress(0) & " " & cur.someOtherDistinctiveFieldFromUserDoc(0) '& more fields if you need more distinction, but be sure this is unique for each document, because duplicates wont be visible

                        'add document in our list (using the large key defined above) for later field retrieval
                        lstUsers( arrUsers( i ) ) = cur

                        i = i + 1
                        Set cur = c.GetNextDocument( cur )
                Loop

                response = w.Prompt( 4, "Select user", "Multiple users with the same name found. Select the correct one:", arrUsers(0), arrUsers )
                If Isempty( response ) Then
                        Messagebox "Cancelation", , "User was not chosen"
                Else
                        Set cur = lstUsers( CStr( response ) ) 'lookup document by key from our list
                End If
        End If

        'now cur is our document, regardless of whether we found one or more in view
        'pull data you want from it

Open in new window



Ask if this is too complicated...
0
 
LVL 22

Accepted Solution

by:
mbonaci earned 1300 total points
ID: 34194867
The line 12 is missing an argument, so it should be:

Set c = getAllUserDocumentsFromNAB( commonName )

Open in new window

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This is an old article, please see an updated version of this article, located here: http://www.experts-exchange.com/articles/23619/Notes-8-5x-Windows-7-Notes-info-and-tips.html
  In today’s Arena we can’t imagine our lives without Internet as we are highly used to of it. If we consider our life style just for only 2 min we found that face to face communication is swapped by e-communication.  Every Where from Works place to…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

610 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