Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
// 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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Check the JavaScript console by pressing Ctrl + J to see if there are any errors.
Copy link to clipboard
Copied
This is the message I'm getting:
2:Field:Calculate
TypeError: getField(...) is null
Copy link to clipboard
Copied
That means you specified the wrong field name. Keep in mind that JS is case-sensitive and that you have to use the EXACT field name as it appears in your form, including spaces, underlines, etc.
Copy link to clipboard
Copied
That wasn't the issue. Turns out all I had to do was to change the values of First_Name, Middle_Name and Last_Name to s1, s2 and s3. Thanks for all the responses.
Copy link to clipboard
Copied
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
This approach avoids extra spaces or other separators when there are fields with null strings for a value.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now