Skip to main content
Participant
Dec 7, 2016 7:37 PM UTC
Answered

Extracting last and first initial into another field

Hello -

I'm having some difficulties with Javascript and was hoping someone could help.

I have a full name field (Field Name: Project_Initiator) and would like to extract the last name and first initial into another field  (i.e. Dan Smith = Smith, D.).

I am using Adobe Acrobat XI Pro Mac.

Thank you for your help.

This topic is closed to new replies. Start a new post to keep the conversation going.
try67
try67Correct answer
Community Expert
Dec 7, 2016 7:55 PM UTC

OK, then you can use this code as the custom calculation script of the Initial field:

var fullName = this.getField("Project_Initiator").valueAsString;

if (fullName=="") event.value = "";

else {

    var names = fullName.split(" ");

    event.value = names[names.length-1] + ", " + names[0].substring(0,1)+".";  

}

7 replies

try67
Community Expert
Community Expert
Dec 7, 2016 7:42 PM UTC

What if someone fills in three names? How will you know if it's two first names, or two last names?

I would recommend you don't do this automatically. It's too risky and if you get it wrong people can get really pissed off.

Translate
DSM0802Author
Participant
Dec 7, 2016 7:48 PM UTC

It's internal - and for my use only.

Translate
try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
Dec 7, 2016 7:55 PM UTC

OK, then you can use this code as the custom calculation script of the Initial field:

var fullName = this.getField("Project_Initiator").valueAsString;

if (fullName=="") event.value = "";

else {

    var names = fullName.split(" ");

    event.value = names[names.length-1] + ", " + names[0].substring(0,1)+".";  

}

Translate