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

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

New Here ,
Jun 29, 2020 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.]

TOPICS
Acrobat SDK and JavaScript

Views

310

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

correct answers 2 Correct answers

Community Expert , Jun 29, 2020 Jun 29, 2020

Try this:

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

Likes

Translate

Translate
Community Expert , Jul 03, 2020 Jul 03, 2020

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());  
...

Likes

Translate

Translate
Community Expert ,
Jun 29, 2020 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
community guidelines
New Here ,
Jun 30, 2020 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
community guidelines
Community Expert ,
Jul 03, 2020 Jul 03, 2020

Copy link to clipboard

Copied

LATEST

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
community guidelines