Notes Ninjas Notes Ninjas
Lotus Notes hints, tips, error messages
Extracting Surname or Lastname from Lotus Notes Abbreviated Name

Hint Short Cut: Add this to your code & documentation to help you find this page.
http://www.notesninjas.com/#Surname or http://www.notesninjas.com/A555F9/nn.nsf/ByAlias/Surname

Grabbing a user's surname


This is a tricky one, and after years of evolution, this is what came out.

The code will work in view columns and fields.

It has been tested on abbreviated names with initials with and without dots and "de la" and "la" such as:

Adam Foster/BizUnit/Company

Adam J D Foster/BizUnit/Company

Adam J Foster/BizUnit/Company

Adam J. D. Foster/BizUnit/Company

Ext-Adam Foster/BizUnit/Company

Adam De La Soul/BizUnit/Company

Adam La Foster/BizUnit/Company

Adam De Foster/BizUnit/Company

Adam J. De Foster/BizUnit/Company

Adam J De Foster/BizUnit/Company

If the common name version has more than 4 components then you are in trouble, as this code will not handle it.

The @function code:

cn:=@Name([CN]; EmployeeName);
nl:=@Explode(@Trim(cn); " ");
@If(@Elements(nl)=1;
cn;
@Elements(nl)=2;
@RightBack(cn;" ");
@Elements(nl)=3;
@If(@RightBack(@Subset(@Subset(nl;2);-1);1)="." | @Length(@Subset(@Subset(nl;2);-1))=1;
@RightBack(cn;" ");
@Right(cn;" "));
@Elements(nl)=4;
@If(@RightBack(@Subset(@Subset(nl;2);-1);1)="." | @Length(@Subset(@Subset(nl;2);-1))=1;

@If(@RightBack(@Subset(@Subset(nl;3);-1);1)="." | @Length(@Subset(@Subset(nl;3);-1))=1;
@RightBack(cn;" ");

@Implode(@Subset(nl;-2);" "));
@Right(cn;" "));
@Right(cn; " ")
)

The lotusscript version.

Adam Foster/BizUnit/Company

Adam J D Foster/BizUnit/Company

Adam J Foster/BizUnit/Company

Adam J. D. Foster/BizUnit/Company

Ext-Adam Foster/BizUnit/Company

Adam De La Soul/BizUnit/Company

Adam La Foster/BizUnit/Company

Adam De Foster/BizUnit/Company

Adam J. De Foster/BizUnit/Company

Adam J De Foster/BizUnit/Company

It does not have the same sophistication but will work in most cases.

Set nn = New notesname(doc.EmployeeName(0))
cname = nn.common
space1=Instr(1, cname," ")
space2=Instr(space1+1,cname," ")

first = Left(cname, space1-1)
If space2=0 Then
last=Right(cname, Len(cname)-space1)
Else
last=Right(cname, Len(cname)-space2)
middle=Mid(cname,space1+1,space2-space1-1)
If Len(middle) =1 Or Right(middle,1)="." Then
first = first+" "+middle
Else
last =middle+" "+last
End If
End If

'last contains the last name, and first contains firstname (and initial)

 

 Jump to:     Notes Tips
    Lotus Notes Index 
  Register for Tips
Previous Lotus Notes Tip 
    Next Lotus Notes Tip
Your company logo here?
Adam Foster
Free Cash Making Web Site
Free Revenue Earning Blog Site
 Free Revenue Earning Newsletter Site   
Free Search Pages Free Web stats
Free Contact Us page
Cheap .com domain names
 Need a website or 
   Lotus Notes
  problem solved?
Adam Foster
Lotus Notes 5 All-in-one Certification Exam Guide by Libby Schwarz, Ben Malekzadeh
Sort out your CLP with this book.
See at: Amazon.co.uk | Amazon.com |