Skip to main content
Participant
October 6, 2016
Question

Combine Fields

  • October 6, 2016
  • 2 replies
  • 598 views

I have 3 separate fields for First name, Middle Initial and Last Name. I'd like to combine all the fields into one field in the same PDF.

This topic has been closed for replies.

2 replies

Inspiring
October 7, 2016

I would use 2 document level functions. The first would combine the fields but not include any field with a null value and include a separator value as needed. The other function would bet the field object and report any field that could not found by name.

https://www.dropbox.com/s/lqwo2clnb7pfjar/Concatinate%20Name%20and%20Address.pdf?dl=0

Concatenate Name and Address

This approach avoids extra spaces or other separators when there are fields with null strings for a value.

Participant
October 6, 2016

// Get the field values, as strings

var First_Name = getField("First_Name").valueAsString;

var Middle_Name = getField("Middle_Name").valueAsString;

var Last_Name = getField("Last_Name").valueAsString;

// Combine values, separated by a space

if(getField("Middle_Name").value == ""){

    event.value = First_Name + " " + Last_Name

}

else {

    event.value = First_Name + " " + Middle_Name + " " + Last_Name

}

This goes into the calculate> Custom Script and this script is if you don't have a middle name it wont look funny

Participant
October 6, 2016

I see what you did there, and the attention to the middle name is a nice touch, but something's not quite right. The field is coming up empty.

Inspiring
October 6, 2016

Check the JavaScript console by pressing Ctrl + J to see if there are any errors.