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

Custom copy in the body of the Return email...

clibor
Registered: Aug 30 2010
Posts: 17
Answered

To anybody that can help. I came up with the script below. It WORKS! If I wasn't so detail driven I'd live with it. I would like to add more to it but I'm stuck.
Review the script below. I'll meet you at the bottom.
 
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.
 
SO LIKE I SAID BEFORE...SCRIPT WORKS PERFECTLY FINE!
 
Now I want to add a few more features.
If you go back to step 6.
"The email body is also filled in with preset copy together with "CustName" & "BoxID".
 
In the actual form I've created there are actually about a couple dozen fields.
The "CustName" and "BoxID" fields are the only 2 that are required. I would like a way of adding to the script that shows the remaining fields to show "TBA" in the body of the email IF it's not filled in.
 
I'm stumped and stuck on this one.
 
CLIFF
  

My Product Information:
Acrobat Pro 9.2, Macintosh
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Just get the value of those other fields and if they're blank, use "TBA instead. For example:

var v3 = getField("some_other_field").valueAsString;
if (v3 === "") v3 = "TBA";

then use the variable v3 to build the body of your email.


BTW, if you're working with text fields, the following code:

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

can be replaced with:

getField("CustName").valueAsString !== ""


Comparing a field value to the special JavaScript value of null is misleading, since no type of field other than a digital signature field will ever return a value of null. When comparing a blank value (zero length string) to null using !=, null will get typecasted to false, as will the zero length string, so it works, but it's unnecessary and misleading.
clibor
Registered: Aug 30 2010
Posts: 17
I'm not sure how I use the variable v3 to build the body of my email or even where I should place the script.
I understand how it should work just not sure how to make it work.
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Well, you have this already:

var cBody = "Please Process order. \n" +
"\n" +
"CUSTOMER NAME: " +
this.getField("CustName").value + "\n" +
"BOX ID: " +
this.getField("BoxID").value

So you could just continue building the string:

var v3 = getField("some_other_field").valueAsString;
if (v3 === "") v3 = "TBA";

var cBody = "Please Process order. \n" +
"\n" +
"CUSTOMER NAME: " +
this.getField("CustName").value + "\n" +
"BOX ID: " +
this.getField("BoxID").value + "\n" +
"DESCRIPTION HERE: " + v3;




clibor
Registered: Aug 30 2010
Posts: 17
Thanks George!

Works perfect! I really appreciate your help..

CLIFF