Skip to main content
DRAII
Participant
January 11, 2019
Question

Multi-level PDF Validation

  • January 11, 2019
  • 1 reply
  • 265 views

Hello everyone! I could use some help with a PDF document script.

Let me explain my document a bit...

I have a Weekly Checklist for my management team and it's formatted as a PDF Form. It's about 19 questions where the manager has to chose either "Yes", "No", or "N/A" from a drop down box. Any response that would be an exception from the acceptable answer requires an explanation in the comment section text field. Example: For Question 1, if the manager selects "No" when it should be "Yes" they are required to explain why in the comment section. Once all of the questions have been answered, I have a Email button that currently only checks to ensure the name and employee number is present. Once that's validated (whether it's there or not) a dialog box opens that would allow you to send the document to me as a PDF. It then resets the document.

Here's what I would like...

I would like to have a custom validation script set up that checks each one of the questions for the appropriate response which would then prompt them to enter a response in the comment section. Then, once those conditions are met, you can then email the document using the submit button.

The Fields are labeled as follows: Dropdown1 and Comments1 all the way to Dropdown19 Comments19.

How would I go about writing this script?

Here's what I have so far on the Submit button

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: "email address@email.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."

   

});

Thank you for reading and thanks again in advance for your help!

This topic has been closed for replies.

1 reply

Legend
January 11, 2019

Looks like a start, except that you do

if ( <bad things> )

{

tell_the_user

}

do_other_stuff

Naturally, after telling the user it will do the other stuff anyway. You probably should consider:

if ( <bad things> )

{

tell_the_user

}

else

{

  do_other_stuff

}