Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Combine Fields

New Here ,
Oct 06, 2016 Oct 06, 2016

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.

TOPICS
Acrobat SDK and JavaScript , Windows
504
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 06, 2016 Oct 06, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 06, 2016 Oct 06, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 06, 2016 Oct 06, 2016

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 07, 2016 Oct 07, 2016

This is the message I'm getting:

2:Field:Calculate

TypeError: getField(...) is null

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 07, 2016 Oct 07, 2016

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 07, 2016 Oct 07, 2016

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 07, 2016 Oct 07, 2016
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines