These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Validate Script > Then Save As > Then attach as an email.

clibor
Registered: Aug 30 2010
Posts: 17
Answered

So here's my script. It's added to a submit button as an action that I've created and set to save as first before this script executes.
  
var cToAddr = "IPG-VORD [at] imagepac [dot] com";
 

var cSubLine = "New Order: " +
this.getField("Customer Name").value +
" - " +
this.getField("Box ID").value;
var cBody = "Please Process order. \n" +
"\n" +
"CUSTOMER NAME: " +
this.getField("Customer Name").value + "\n" +
"BOX ID: " +
this.getField("Box ID").value

this.mailDoc({bUI: true, cTo: cToAddr, cSubject: cSubLine, cMsg: cBody});
 
Everything works perfect! EXCEPT, I would like to validate the "Customer Name" & Box ID" fields before the save as command commences.
I'm not using a script for "Save As" but using the Execute a Menu Item.
 
Basically here's the order of what should happen.
 
1. Hit the SUBMIT BUTTON.
2. If the "Customer Name" & Box ID" are filled in, Save as then execute the above
script.
3. If not, then a pop up box saying the fields should be filled in prior to
submitting form.
  
NOTE: What the above script does is show a return address and the attached PDF
form with a subject line based on the "Customer Name" & "Box ID" Field as
well as the body of the email.
 
Any help would be appreciated.
 
CLIFF

My Product Information:
Acrobat Pro 9.2, Macintosh
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
If you want to do that, you will have to disable the submit button (maybe grey it out and make it read-only) until the two fields have a value. You could call a script form each of these field's Validate event that checks the values and enable/disables the submit button.

You could also set up a dummy button at the same location as the real submit button so that when it is clicked it will display the error message. The dummy button would get hidden when the two fields have values. If you do this, you would simply hide the real submit button when the dummy should be shown, and vice versa.
clibor
Registered: Aug 30 2010
Posts: 17
Just in case anyone needs this script here it is.

if (this.getField("CustName").value !=null &&
this.getField("CustName").value!="" &&
this.getField("BoxID").value !=null &&
this.getField("BoxID").value!="")

{
app.execMenuItem("SaveAs");

var cToAddr = "IPG-VORD [at] imagepac [dot] com";var cSubLine = "New Order: " +
this.getField("CustName").value +
" - " +
this.getField("BoxID").value;
var cBody = "Please Process order. \n" +
"\n" +
"CUSTOMER NAME: " +
this.getField("CustName").value + "\n" +
"BOX ID: " +
this.getField("BoxID").value


this.mailDoc({bUI: true, cTo: cToAddr, cSubject: cSubLine, cMsg: cBody});
}
else {app.alert("Although we prefer you fill in the form with as much information as you can. We at least need the Customer Name and a Box ID filled in before you can submit this order.");}



Here's what the script does when used as a Mouse up action for a button.

1. Click Button.
2. If "CustName" & "BoxID" field are filled in then the "Save As" executes.
3. Once "Save as" is completed the email client opens.
4. The "TO" email address is set.
5. The Subject header is filled in based on the "CustName" & "BoxID" field.
6. The email body is also filled in with preset copy together with "CustName" & "BoxID".
7. PDF form is attached as well.

IF "CustName" & "BoxID" is not filled then a Javascript warning pops up and asks you to fill these fields in before you can proceed further.Hope this helps anyone who needs control of where the form is being emailed to as well as what the email should say.

CLIFF