Separating First Middle And Last Name From Address Book

A lookup can be done to the address book to absolutely get the first middle and last name via lookups.

For some time I have used @LeftBack and @RightBack against the Common Name form of a user name to produce lastname, firstname mi but - - what if the user's last name ie two parts with a SPACE - no other character? using @RightBack(@Name([cn];@UserName)) + ", " + @LeftBack(@Name([cn];@UserName)) If the user's name is John Public or John Q Public or J Quincy Public, this works.

But what if you get a last name like Van Olsen? Then you get Olsen, John Q Van!!!!!!! The following code seems to do the trick - unless someone had a two part first name (gasp)

The trick here is to take the common name and find out how many words it is using the space as the separator. If only two words then it can only be a first name/initial and last name. J Public or John Public If 4 words than it must be a first name/initial middle name/initial and a two part last name. J Q Van Public John Q Van Public etc. If three words then we only need to check if the length of BOTH the first AND second words are longer than 1. If so than it has to be a first name and 2 part last name (on the assumption that people go bo either their first OR middle name and the other is an initial). John Van Public. If this is not true and there are three words than it must be: J Van Quincy or John Van Quincy.

The following code performs this function and separates each word into appropriate hidden fields on a form which can then be used however the programmer desires. Temporary variables could have been used but this gave me the ability to use the first, middle and last name in computed for display fields and in views as desired.

One additional tip - if your address book has a person's suffix (Jr., Sr, IV, etc.) you can first check if the user's name contains a comma and then use @LeftBack and @RightBack to get the suffix and full name separated into two temporary variables. then perform the following on the full name and concantinate the suffix at the end if needed.

With some script or even formula language, a lookup can be done to the address book to absolutely get the first middle and last name via lookups. With the improvements in indexing on R4 and R5 this is now pretty fast. You can use the abbreviated version of the users name and then lookup to the ($Users) view in the server address book which is indexed by user names. The abbreviated name is definately a unique name and you can easily get the firstName, MiddleInitial, LastName fields from the person document.

I wrote this to work with names that were not otherwise in a form that could reliably provide a unique "notes" name because they were common name only and "duplicate" names could be found (ie: two John D Blair's) or where a name was simply entered by the user in a text field and they are Mike Jones instead of Michael B Jones.

This code assumes the user does NOT have a two part First or Middle Name (ie: Billy Joe K Smith would not be properly sorted by this code.) The code can also be revised to use temporary fields by substituting CName:=""; for FIELD CName:=CName; etc. and then using @Set for @SetField, etc. if you don't need to actualy save the first, middle or Last names on the documents.

You can expand this for 5 word names like John Q Van der walde

Comment: Taking the common name of a user and then using @RightBack & @LeftBack to find everything to the right and left of the first space works - until you get a last name like Von Ryan or Van Pelt or Du Pont. You get Ryan, John Q Von instead of Von Ryan, John Q

This formula gets around this

Formula:

REM "Place the following fields on the form and initialize them";
REM "If the common name is already provided on your form you can eliminate the";
REM "FIELD CName:=CName statement, the CommonName:= statement and";
REM "the @SetField("CName . . statements.";
REM "Then substitute your existing field name wherever CommonName is used here";

FIELD CName:=CName;
FIELD Words:=Words;
FIELD FirstName:=FirstName;
FIELD MidInit:=MidInit;
FIELD LastName:=LastName;
CommonName:=@Name([CN];@UserName);
NWords:=@Elements(@Explode(CommonName;" "));
@SetField("CName";CommonName);
@SetField("Words";NWords);

REM "If there are only 2 words then it must be John Public or J Public.";
REM "If there are 3 words, first see of the first and second words are BOTH greater 
that 1 in length."; REM "If so then is must be John Van Public."; REM "If Not and still 3 words then it must be John Q Public or J Quincy Public."; REM "If there are 4 words then it must be J Q Van Public, John Q Van Public or
J Quincy Van Public."; @If(NWords=2;@Do( @SetField("FirstName";@Word(CommonName;" ";1));@SetField("MidInit";"");@SetField
("LastName";@Word(CommonName;" ";2))); NWords=3 & @Length(@Word(CommonName;" ";1))>1 & @Length(@Word(CommonName;" ";2))>1;@Do( @SetField("FirstName";@Word(CommonName;" ";1));@SetField("MidInit";"");@SetField("LastName";
@Word(CommonName;" ";2) + " " + @Word(CommonName;" ";3))); NWords=3 ;@Do( @SetField("FirstName";@Word(CommonName;" ";1));@SetField("MidInit";@Word(CommonName;" ";2))
;@SetField("LastName";@Word(CommonName;" ";3))); NWords=4 ;@Do( @SetField("FirstName";@Word(CommonName;" ";1));@SetField("MidInit";@Word(CommonName;" ";2));
@SetField("LastName";@Word(CommonName;" ";3) + " " + @Word(CommonName;" ";4))); "")

Dig Deeper on Domino Resources

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchDataCenter

SearchContentManagement

Close