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 28, 2016

When you run the script, you are getting an error message on the console:

ReferenceError: Patient_Last_Name is not defined

2:Field:Mouse Up

The reason for this is that the Doc.getField() method expects a string as it's parameter (see here for more information: Acrobat DC SDK Documentation ) - you are however only providing an undefined variable (at least that's what the interpreter sees). In addition to this, just getting the field is not sufficient to get it's value, you need to access the field's "value" property. I've modified your code so that it should work:

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({

  bUI: true,

  cTo: cToAddr,

  cSubject: cSubLine,

  cMsg: cBody

});

In general, whenever you are not getting what you are expecting, the first step should be to check the JavaScript console for errors. Use Ctrl-J or Cmd-J to display the console window.