Adobe Form JavaScript
Copy link to clipboard
Copied
I'd like to use the "Submit" button I created to run a Javascript that will compose an email with the following form fields pulled in and attach the completed form as a PDF.
To - Field Name "All submissions automatically sent to"
CC - Field Names "Email of Staff Submitting Form"; "Email of First Approver"; "Email of Second Approver"
Subject - Field Name "Start Date" + Field Name "Legal Name"
Body - Attached please find the hiring authorization form, pending approval, for Field Name "Legal Name".
Additionally, I'd like to form to attach with a new title: Hiring Authorization Form - Field Name "Legal Name".
Below is the start to the Javascript I attempted to use, but it is not opening an email when I hit submit.
var cTo = this.getField ("All submissions automatically sent to").value;
var cCc = this.getField ("Email of Staff Submitting Form").value + this.getField("Email of First Approver").value + this.getField("Email of Second Approver");
var cSubject = this.getField ("Start Date").value + this.getField("Legal Name").value;
var cBody = "Attached please find the hiring authorization form, pending approval, for " + this.getField("Legal Name").value;
event.target.mailDoc({bUI: true, cTo: cToAddr, cCc: cCCAddr, cSubject: cSubLine, cMsg: cBody});
I'm hopeful someone might be able to see where I went wrong, or tell me what script I should be using!
Thank you.
Copy link to clipboard
Copied
First, there's an error in your script because there is no field called "Start Date". Next, you define variables (cTo, cCc, cSubject) that are already parameters in the method. This will cause errors. Last, you call variables that are not defined (cToAddr, cCCaddr, cSubLine). These should be the variables.
In order to change the name of the file that attaches, you must first save the document with the new file name. This can't be done 'silently' and requires a privileged context.
Copy link to clipboard
Copied
Thank you for the reply. I've changed it so there is a "Start Date" field now. I am very unfamiliar with how JavaScript works, so I was hopeful that someone might be able to use the identified fields I mention and put it into a script that will generate an email and pull the fields mentioned. Is this something you might be able to help with?
Copy link to clipboard
Copied
The code you posted already does that. You just need to make sure it contains no errors like the one mentioned above, and it should work.
Copy link to clipboard
Copied
ar cToAddr = this.getField ("All submissions automatically sent to").value;
var cCCAddr = this.getField ("Email of Staff Submitting Form").value + this.getField("Email of First Approver").value + this.getField("Email of Second Approver");
var cSubLine = this.getField ("Start Date").value + this.getField("Legal Name").value;
var cBody = "Attached please find the hiring authorization form, pending approval, for " + this.getField("Legal Name").value;
this.mailDoc({bUI: true, cTo: cToAddr, cCc: cCCAddr, cSubject: cSubLine, cMsg: cBody});
Copy link to clipboard
Copied
I'm still getting an error on the highlighted piece and I'm not sure how to fix it.
Copy link to clipboard
Copied
At the first line change ar to var.
Copy link to clipboard
Copied
I fixed it to "var". When I hit the submit button, I am getting the attached message. Any idea why?
Copy link to clipboard
Copied
You have to separate multiple email addresses with semi-colons:
var cCCAddr = this.getField ("Email of Staff Submitting Form").value +";"+ this.getField("Email of First Approver").value +";"+ this.getField("Email of Second Approver").value;
Also this.getField("Email of Second Approver"); should be this.getField("Email of Second Approver").value; That's why you're getting [object field]. It's calling the field, not the value of the field.
Copy link to clipboard
Copied
Thank you! I got that to work. One final question, can someone help wtih the specific script to rename the pdf file that attaches to the email?
Copy link to clipboard
Copied
this.saveAs(this.path.replace(this.documentFileName, "The new file name"+".pdf"));
As mentioned previously, saving silently like this requires a privileged context (console, batch, or trusted function in a folder level script). In this case you would write a trusted function, save it in the application JavaScripts folder, and call the function in your button prior to the email script.
Copy link to clipboard
Copied
You must place a semi-colon between the addresses. Also, you've accessed a field instead of its value in the last part of this line:
var cCCAddr = this.getField ("Email of Staff Submitting Form").value + this.getField("Email of First Approver").value + this.getField("Email of Second Approver");
It should be:
var cCCAddr = this.getField ("Email of Staff Submitting Form").value + ";" + this.getField("Email of First Approver").value + ";" + this.getField("Email of Second Approver").value;
Copy link to clipboard
Copied
Thank you all for all your help so far. My final ask is about ensuring that all required fields are completed before the javascript runs the email command. Can someone help with this? The required field names are provided below with the field type in parantheses:
- Position Type (drop down)
- Legal Name (text field)
- Mentor (text field)
- Position (text field)
- Primary Cost Center (text field)
- Division (drop down)
- Primary Physical Location (drop down)
- Program/Team (text field)
- Team Leader (text field)
- Program Manager (text field)
- Start Date (date field)
- Division Director (text field)
- FLSA (radio button)
- Hourly Rate or Annual Salary (text field)
- Scheduled Pay Period Hours (text field)
- Email of Staff Submitting Form (text field)
- Email of First Approver (text field)
- Email of Second Approver (text field)
- Scheduling Location 1 (drop down)
- EMR - Supervisor Role (drop down)
- Credentials (text field)
- Key Fob Location 1 (drop down)
- Access Needed Location 1 (drop down)
- Network Folder Access Needed (text field)
- Email Distribution Groups Needed (text field)
Please let me know if you need other information.

