Skip to main content
Participant
June 29, 2020
Answered

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

  • June 29, 2020
  • 2 replies
  • 2115 views

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.]

This topic has been closed for replies.
Correct answer ls_rbls

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 ="";

 

 

 

 

2 replies

ls_rbls
Community Expert
ls_rblsCommunity ExpertCorrect answer
Community Expert
July 3, 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());  
    event.value = util.printd("mm.dd.yyyy", d);  

} 
else  event.value ="";

 

 

 

 

Bernd Alheit
Community Expert
Community Expert
June 29, 2020

Try this:

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

Participant
June 30, 2020

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