Question

I am using @NameLookUp formula to retrieve internet address by giving a search key and it is working fine.But now i want to retrive not only the internet address but also some other properties like FirstName and LastName. Here is the formula i am using to @Namelookup internet address by giving search string.

Vector vec=m_session.evaluate("@NameLookup([NoUpdate];\""+ userName + "\"; \"InternetAddress\")");

//username is the String variable(Search Criteria)

Can anyone please help how to retrieve multiple properties(like firstName and lastName along with InternetAddress) by evaluate the formula only once. If it cant be done using @Namelookup is there any other way..?

Was it helpful?

Solution

This is a typical example when using evaluate() to call a Formula is not a good idea. What you want to do is to get the NotesDocument class and read values from it.

Something like this (disclaimer, I am not a Java developer):

// Open Domino Directory on specified server
Database db = session.getDatabase("YourServer/Domain", "names.nsf");
// Get a view with user name is sorted first column
View view = db.getView("($Users)");
// Get the person document for specified user
Document doc = view.getDocumentByKey(userName, true);
if (doc != null) {
   // Get text values from Notes document
   String emailAddress = doc.getItemValueString("InternetAddress");
   String officePhone = doc.getItemValueString("OfficeNumber");
   String officeAddress = doc.getItemValueString("OfficeStreetAddress");
}

I believe this would be faster than multiple lookups using evaluate(), and you also have the added benefit of full error handling, and all being native code.

OTHER TIPS

@NameLookup only returns the value of one item per call.

Assuming your goal is to only have one Evaluate statement, you could chain the calls together and return an array of values in a certain order:

Vector vec=m_session.evaluate("FirstName := @NameLookup([NoUpdate];\""+ userName + "\"; \"FirstName\"); LastName:= @NameLookup([NoUpdate];\""+ userName + "\"; \"LastName\"); InternetAddress :=@NameLookup([NoUpdate];\""+ userName + "\"; \"InternetAddress\"); FirstName:LastName:InternetAddress");

Or possibly:

String firstName = m_session.evaluate("@NameLookup([NoUpdate];\""+ userName + "\"; \"FirstName\")");
String lastName = m_session.evaluate("@NameLookup([NoUpdate];\""+ userName + "\"; \"LastName\")");
String internetAddress = m_session.evaluate("@NameLookup([NoUpdate];\""+ userName + "\"; \"InternetAddress\")");

And then add those three strings in any order into your Vector.

Another approach is to use the DirectoryNavigator class. I believe it's been available since Notes/Domino 8.5 (perhaps even before that). DirectoryNavigator uses some of the same core logic as @NameLookup, so it should perform well.

Here's some sample code. I haven't tested this exact code, but I adapted it from production code that does a similar lookup:

    String firstName = null;
    String lastName = null;
    String inetAddress = null;

    Vector<String> lookupItems = new Vector<String>();
    lookupItems.addElement("FirstName");
    lookupItems.addElement("LastName");
    lookupItems.addElement("InternetAddress");

    Vector<String> vName = new Vector<String>();
    vName.addElement(userName);

    Directory dir = session.getDirectory();
    DirectoryNavigator dirNav = dir.lookupNames("($Users)", vName, lookupItems, true);
    if( dirNav != null && dirNav.getCurrentMatches() != 0 ) {

        // Digest the results of the lookup

        Vector<String> value = null;
        value = dirNav.getFirstItemValue();
        firstName = value.elementAt(0);

        value = dirNav.getNextItemValue();
        lastName = value.elementAt(0);

        value = dirNav.getNextItemValue();
        inetAddress = value.elementAt(0);
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top