Skip to main content
December 26, 2016
Question

Help with JavaScript to Submit Form via Email!

  • December 26, 2016
  • 1 reply
  • 6769 views

Using Adobe Acrobat Pro XI, I am working on a medical form form notifying our medical team of new patients. Upon completion of the form, I am trying to set it up to use a button to submit the saved PDF form and send it to our medical team in an email (we use MS Outlook across the organization). I've found multiple scripts that get me close to what I'm looking for, but I'm trying to accomplish this task with the following parameters:

Email To: "medical_team@outlook.com"

Subject Line: "Patient Notification Form - [LastName, FirstName Rank]"

Attach as: PDF

Body / Message: "Please find the attached Patient Notification Form for [LastName, FirstName Rank] attached."

Form Field Names: 

     - Last Name: Pull from form field "Patient_Last_Name" 

     - First Name: Pull from form field "Patient_First_Name" 

     - Rank: Pull from form field "Patient_Rank" Any help would be greatly appreciated!

This topic has been closed for replies.

1 reply

Karl Heinz  Kremer
Community Expert
Community Expert
December 28, 2016

You said that you are already using a script that got you close. What is missing? Please post the script and let us know what is not yet working correctly. It's much easier to fix an existing solution than to come up with one from scratch, so you will save both us and yourself some time by providing what you are already working with.

December 28, 2016

The requirements have actually changed slightly since my original post. The only difference that instead of rank, the team I am helping develop this form wants the Patient's Service (this is for the military). Basically, they are looking for the following:

Subject: Patient Notification Form - LastName, First Name (Service)

Body: Please find the attached Patient Notification Form for LastName, FirstName (Service).

Form Field Names:

LastName = Patient_Last_Name

FirstName = Patient_First_Name

Service = Patient_Service

The following script works in that it opens an email dialogue with the form attached:

var cToAddr = "medicalteam@mil"

var cSubLine = "Patient Notification Form"

var cBody = "Please find the attached Patient Notification Form"

this.mailDoc({bUI: true, cTo: cToAddr, cSubject: cSubLine, cMsg: cBody});

When I attempt to add the form field data, that is where I run into problems. Here is one of the scripts used most recently. Adobe accepts the script and lets me save it without producing any errors, but when the button is clicked, nothing happens.

var cToAddr = "medicalteam@mil"
var cSubLine = "Patient Notification Form - " + this.getField(Patient_Last_Name) + ", " + this.getField(Patient_First_Name) + " " + this.getField((Patient_Service))

var cBody = "Please find the attached Patient Notification Form for " + this.getField(Patient_Last_Name) + ", " + this.getField(Patient_First_Name) + " " + this.getField((Patient_Service))

this.mailDoc({bUI: true, cTo: cToAddr, cSubject: cSubLine, cMsg: cBody});

Karl Heinz  Kremer
Community Expert
Community Expert
December 29, 2016

CLASSIFICATION: UNCLASSIFIED

Thanks for the advice so far! I really do appreciate it.

Below is the current JavaScript:

var cToAddr = "medicalteam@mil";

var cSubLine = "Patient Notification Form - " + this.getField("Patient_Last_Name").value + ", " + this.getField("Patient_First_Name").value + " " + this.getField("Patient_Service").value;

var cBody = "Please find the attached Patient Notification Form for " + this.getField("Patient_Last_Name").value + ", " + this.getField("Patient_First_Name").value + " " + this.getField("Patient_Service").value;

this.mailDoc();

And here is the JavaScript Debugger Output:

Acrobat EScript Built-in Functions Version 11.0

Acrobat SOAP 11.0

ReferenceError: Patient_Last_Name is not defined

2:Field:Mouse Up

ReferenceError: Patient_Last_Name is not defined

2:Field:Mouse Up

ReferenceError: Patient_Last_Name is not defined

2:Field:Mouse Up

SyntaxError: missing ; before statement

5:

SyntaxError: missing ; before statement

5:

SyntaxError: missing ; before statement

6:

SyntaxError: missing ; before statement

6:

SyntaxError: missing variable name

2:

SyntaxError: missing ; before statement

6:

GeneralError: Operation failed.

Doc.mailDoc:9:Field Submit_PNF:Mouse Up

CLASSIFICATION: UNCLASSIFIED


The last line just calls this.mailDoc() without any arguments, so your

"To", "Subject" and "Body" information is not getting used.

There is nothing in these lines that could generate the error message you

are seeing. You have some strange line breaks in the quoted script, I

assume that you are not breaking within a string, and that this is just due

to how the mail application formatted the code.

In Acrobat, you can get a list of all JavaScript that is in a document, you

do this via the "All JavaScripts" function in Tools>JavaScript. I would

pull that up and see if you have any more instances of referencing the

field names without the quotes around them.