Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Truncate Text in Adobe Acrobat

Community Beginner ,
May 03, 2021 May 03, 2021

Copy link to clipboard

Copied

Hi there

 

Trying to create a form to where in one cell, they place the person's name - Chandler, Michael Stevens

 

Then another cell references that cell, and I want it to just have Chandler and anything after the , is truncated. I tried to search online for this but the formula I found does not work 100%. Any help would be greatly appreciated. 

TOPICS
Create PDFs, General troubleshooting, How to, PDF forms

Views

569

Likes

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 03, 2021 May 03, 2021

Copy link to clipboard

Copied

You can use this script as a Validation script in the field where they place the person's name:

 

aTexte = event.value;  // get the value
aTexte = aTexte.split(" ");  // use the blank space to split the value into array
aTexte = aTexte.shift();  // get the first element of the array
aTexte = aTexte.replace(",", "");  // remove the comma if exist
this.getField("targetTextFieldName").value = aTexte;  // assign the resulting value to the target field

Likes

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 03, 2021 May 03, 2021

Copy link to clipboard

Copied

You are awesome! Thank you. Side question.... 
So, another thing I am wanting to see if is possible...

Have a drop down of various salutations:
 Dear Mr. & Mrs..
 Dear Mr. 

 Dear Mrs. & Mrs. 

 

Etc. But, depending on the drop down, have the field that pulls just the last name, to where it reads:

     Dear Mr. & Mrs. Chandler
This will allow for the text to all flow as a normal letter and not a huge gap. Thank you!!

Likes

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 03, 2021 May 03, 2021

Copy link to clipboard

Copied

Instead of the above use this code as the custom calculation script of the text field (adjust the field names as needed in the code):

 

 

var fullName = this.getField("FullName").valueAsString;
var prefix = this.getField("Prefix").valueAsString;
if (fullName!="") {
	var surname = fullName.split(",")[0];
	event.value = prefix + " " + surname;
} else event.value = "";

 

Edit: Code fixed

 

Likes

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 03, 2021 May 03, 2021

Copy link to clipboard

Copied

I am trying the above script but getting the following error. Thank you @TRY - you've helped me on other situations in the past so thank you again!!!

 

image.png

Likes

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 03, 2021 May 03, 2021

Copy link to clipboard

Copied

The screenshot is cut off... But I think I know what it is.

Change this line:

if (fullName!="")

To:

if (fullName!="") {

Likes

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 04, 2021 May 04, 2021

Copy link to clipboard

Copied

You're awesome. Thank you. So curve ball now - say they want to add in their own salutation that may be out of the norm and something no on the list... i.e. Dr. & Mrs or Mr. & Ms. .... a list of possible salutations could become quite lengthy. Cause with this code, if I go in and try to type in my own greeting, it reverts back to what is selected from above. Much thanks and respect for your knowledge!

Likes

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 04, 2021 May 04, 2021

Copy link to clipboard

Copied

LATEST

You can set the drop-down field to accept custom user input, under its Properties - Options tab.

The script will work the same with either a selected value or a manually entered one.

Likes

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