Highlighted

How to pull first character from string and concatenate into text string?

New Here ,
Jun 29, 2020

Copy link to clipboard

Copied

I have a form that is required to be filled out on a daily basis. At the end of the day, it is submitted to an email address (submission@example.com). The email subject line must be in the following format: 06.29.2020.Lastname, F

 

I have three form fields: Date, First and Last. Date is obvious. First is a user's full first name, Last is a user's full last name. My goal is to pull the entire string from Last but only the first character from First.

 

I have the following code in a Submit button on the form:

 

this.mailDoc({cTo: "submission@example.com", cSubject: this.getField("Date").valueAsString + "." + this.getField("Last").valueAsString + ", " + this.getField("First").valueAsString, cMsg: "Attached is blah blah blah for " + this.getField("Date").valueAsString + "."});

 

Currently this will print out "6.29.2020.Last, First"

 

I know I need to modify the "this.getField("First").valueAsString" portion, but I don't know how.

I've tried:

this.getField("First").charAt(0)

this.getField("First").substring(0,1)

and a number of other ugly variations of random things.

 

Can anyone help me modify this line to pull just the first character from "First"?

 

BONUS QUESTION:

The "Date" field currently prints the date in the format of m.d.yyyy.

The subject line format wants the date in the format of mm.dd.yyyy.

Is there a way to modify the date used for just this purpose? Or is there a different function I can use to generate a new date format instead of relying on the "Date" field?

[For the purposes of this question, modification of the "Date" field to print the format mm.dd.yyyy is not a feasible solution.]

Adobe Community Professional
Correct answer by Bernd Alheit | Adobe Community Professional

Try this:

this.getField("First").valueAsString.substr(0,1)

Topics

Acrobat SDK and JavaScript, How to, PDF forms

Views

55

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

How to pull first character from string and concatenate into text string?

New Here ,
Jun 29, 2020

Copy link to clipboard

Copied

I have a form that is required to be filled out on a daily basis. At the end of the day, it is submitted to an email address (submission@example.com). The email subject line must be in the following format: 06.29.2020.Lastname, F

 

I have three form fields: Date, First and Last. Date is obvious. First is a user's full first name, Last is a user's full last name. My goal is to pull the entire string from Last but only the first character from First.

 

I have the following code in a Submit button on the form:

 

this.mailDoc({cTo: "submission@example.com", cSubject: this.getField("Date").valueAsString + "." + this.getField("Last").valueAsString + ", " + this.getField("First").valueAsString, cMsg: "Attached is blah blah blah for " + this.getField("Date").valueAsString + "."});

 

Currently this will print out "6.29.2020.Last, First"

 

I know I need to modify the "this.getField("First").valueAsString" portion, but I don't know how.

I've tried:

this.getField("First").charAt(0)

this.getField("First").substring(0,1)

and a number of other ugly variations of random things.

 

Can anyone help me modify this line to pull just the first character from "First"?

 

BONUS QUESTION:

The "Date" field currently prints the date in the format of m.d.yyyy.

The subject line format wants the date in the format of mm.dd.yyyy.

Is there a way to modify the date used for just this purpose? Or is there a different function I can use to generate a new date format instead of relying on the "Date" field?

[For the purposes of this question, modification of the "Date" field to print the format mm.dd.yyyy is not a feasible solution.]

Adobe Community Professional
Correct answer by Bernd Alheit | Adobe Community Professional

Try this:

this.getField("First").valueAsString.substr(0,1)

Topics

Acrobat SDK and JavaScript, How to, PDF forms

Views

56

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

Copy link to clipboard

Copied

Try this:

this.getField("First").valueAsString.substr(0,1)

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
Reply
Loading...
New Here ,
Jun 30, 2020

Copy link to clipboard

Copied

Brilliant. Thank you so much! Any chance I could ask you about the bonus date question from the original post? 

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
Reply
Loading...
ls_rbls LATEST
Adobe Community Professional ,
Jul 03, 2020

Copy link to clipboard

Copied

To answer  your BONUS question you don't need to modify the Date field since you can apply a custom calculation script in the Subject Line field to grab the date output as a string using util.scand  together with  the setDate(getDate()) method. Then format that string output to whatever custom supported format you want to use with util.printd like this:

 

var date = this.getField("Date").valueAsString;  

if (date !=="")  {
    var d = util.scand("m.d.yyyy", date);  
    d.setDate(d.getDate());  
    event.value = util.printd("mm.dd.yyyy", d);  

} 
else  event.value ="";

 

 

 

 

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
Reply
Loading...
Resources
One Stop Solution for Acrobat
Edit a PDF