Skip to main content
Participating Frequently
July 7, 2025
Question

Adobe Form JavaScript

  • July 7, 2025
  • 1 reply
  • 871 views

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.

1 reply

PDF Automation Station
Community Expert
Community Expert
July 7, 2025

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.

Participating Frequently
July 7, 2025

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?

try67
Community Expert
Community Expert
July 7, 2025

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.