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, Create PDFs, How to, PDF forms

Views

559

Likes

translate

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

Adobe Community Professional , 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 (...

Likes

translate

Translate

Translate
Adobe Community Professional ,
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;

 

 

 

 

 

Likes

translate

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.

Likes

translate

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

Copy link to clipboard

Copied

You're welcome.

Likes

translate

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
Adobe Community Professional ,
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

Likes

translate

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

Copy link to clipboard

Copied

Nice!

 

Thank you.

Likes

translate

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