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
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.