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.
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)