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

Combining multiple field entries into one field OR not

Community Beginner ,
May 26, 2020 May 26, 2020

Copy link to clipboard

Copied

I would like to auto-populate a field in Adobe using the first & last names of the people completing the form as per the following:

DETAILS ENTERED BY CLIENTS ON PAGE ONE

client_names.png 

 

FIELD I NEED TO AUTO POPULATE

authorise.png

 

I am using the following custom calculation script to auto populate "authorisation_1", which works fine when the "firstname2" and "lastname2" fields have been populated:

event.value = getField("firstname1").valueAsString + " " + getField("lastname1").valueAsString + " & " + getField("firstname2").valueAsString + " " + getField("lastname2").valueAsString;

 

However, my question is, how do i ensure the "&" does not appear in "authorisation_1" field IF nothing has been entered into the "firstname2" and "lastname2" fields?

 

NEED TO AVOID THIS

avoid.png

 

Thanks in advance.

TOPICS
Acrobat SDK and JavaScript

Views

1.1K

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , May 26, 2020 May 26, 2020

HI,

 

You may declare variables instead of using the long typing method to make your script more organized and easier to read as an equation if you want (but this just my preference).

 

Then  add an IF/ELSE condition to your custom calculatiopn script. It could be something like this, for example:

 

var name1 = getField("firstname1").valueAsString;
var last1 = getField("lastname1").valueAsString;
var name2 = getField("firstname2").valueAsString; 
var last2 = getField("lastname2").valueAsString;

if  (
...

Votes

Translate

Translate
Community Expert ,
May 26, 2020 May 26, 2020

Copy link to clipboard

Copied

HI,

 

You may declare variables instead of using the long typing method to make your script more organized and easier to read as an equation if you want (but this just my preference).

 

Then  add an IF/ELSE condition to your custom calculatiopn script. It could be something like this, for example:

 

var name1 = getField("firstname1").valueAsString;
var last1 = getField("lastname1").valueAsString;
var name2 = getField("firstname2").valueAsString; 
var last2 = getField("lastname2").valueAsString;

if  (  ( (name1 !="") && (last1 !="") ) && (  (name2 !="") && (last2 !="") )  ) event.value = name1+" "+last1+ " & " + name2+ " "+last2;
else  event.value = name1+" "+last1;

 

 

 

 

 

Votes

Translate

Translate

Report

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 Beginner ,
May 26, 2020 May 26, 2020

Copy link to clipboard

Copied

Hi ls_rbls, 

 

This suggestion worked perfectly... thank you.

Votes

Translate

Translate

Report

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 ,
May 26, 2020 May 26, 2020

Copy link to clipboard

Copied

You're welcome.

Votes

Translate

Translate

Report

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 ,
May 27, 2020 May 27, 2020

Copy link to clipboard

Copied

Hi,

The above answer is correct but could be simplified a little as we always return name1 and last1, so the code could be

 

var finalString = getField("firstname1").valueAsString + " " + getField("lastname1").valueAsString;
var name2 = getField("firstname2").valueAsString; 
var last2 = getField("lastname2").valueAsString;


if ( name2 !="" && last2 !="" ) {
    finalString += " & " + name2+ " "+last2;
}

event.value = finalString;

 

Regards

Malcolm

Votes

Translate

Translate

Report

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 ,
May 27, 2020 May 27, 2020

Copy link to clipboard

Copied

Nice!

 

Thank you.

Votes

Translate

Translate

Report

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 ,
Jun 30, 2022 Jun 30, 2022

Copy link to clipboard

Copied

LATEST

Hi,

Look at line 2 and remove:

 

+ "&"

 

It should work fine.

 

Good Luck

 

Votes

Translate

Translate

Report

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