I have this code I've pieced together linked to an action button in this PDF. It is supposed to verify if all required fields are entered and if so, it will pull the name and employee number from the document and generate an email with the PDF attached. If it fails these checks, there's a pop-up that warns the user of the missing information.
The problem I have is that the when the code runs, you can bypass the warning and still email the document.
How do I adjust this to stop until all of the fields are answered?
Desired "Pseudo code": Check empty fields (get Manager's Name) (get manager's EE nubmer). If required fields (checkbox) and comments are empty, alert user. If it's good, build email subject line and text from these areas...
Here's the code as it stands:
var emptyFields = [];
for (var i = 0; i < this.numFields; i++) {
var f = this.getField(this.getNthFieldName(i));
if (f.type != "button" && f.required) {
if ((f.type == "text" && f.value == "") || (f.type == "checkbox" && f.value == "Off")) emptyFields.push(f.name);
}
}
if (emptyFields.length > 0) {
app.alert("Error! This checklist is incomplete:\n" + emptyFields.join("\n"));
}
// Build the subject line text from several fields form fields
var subj_text = getField("Weekly Management Critical Items:").valueAsString;
subj_text += ": " + getField("Manager Name").value;
subj_text += "- " + getField("Manager EE#").valueAsString;
// Send the email
mailDoc({
cTo: "dennis.aikens@fedex.com",
cSubject: subj_text,
cMsg: "Hey Dennis, here's my checklist for this week. \r" + "Let me know if you have any questions. Thank you."
});
I know it's a little long, so I appreciate you for reading.
Thanks for all your time and input!