Error occurring on PC Adobe Reader 2017, but functioning on Mac Adobe Acrobat DC

Jun 26, 2019

Copy link to clipboard

Copied

I have pieced together Javascript to validate that required forms are filled, if filled, prompt a save as with new name suggestion, and then email submission. It functions properly on Mac Adobe Acrobat Pro DC, but on Windows 10 Adobe Reader 2017, I received on the Javascript debugger "TypeError: f is null 7:Field:Mouse Down"

I have it set on a submit button, Mouse Down, run a JavaScript. It may look pretty messy as I am very novice to this!

Any idea why this would be happening from the script below?

var emptyFields = [];

for (var i=0; i<this.numFields; i++) {

     var f= this.getField(this.getNthFieldName(i));

     if (f.type!="button" && f.required && f.display==display.visible) {

          if ((f.type=="text" && f.value=="" && f.value !== 0) || (f.type=="checkbox" && f.value=="Off")) emptyFields.push(f.name);

     }

}

    if (emptyFields.length>0) {

        app.alert("At least one required field was empty. Fill out the required fields before saving:\n" + emptyFields.join("\n"));

    } else {   

        var newFileName =

("TheFeed_DigitalContentBrief_") +

this.getField("Brand").valueAsString + "_" + this.getField("Market").valueAsString + "_" + this.getField("BriefingDate").valueAsString + ".pdf";

        app.response("Please copy the text below and use it as the new file-name:","", newFileName);

        app.execMenuItem("SaveAs");

this.mailDoc({bUI:false,cTo:"General - TEAMS: The Feed LATAM <042c8d45.nestle.onmicrosoft.com@emea.teams.ms>",cSubject:"New Content Brief from " + this.getField("Market").value + " for " + this.getField("Brand").value, cBody:"Attached new Digital Content Brief, please review."})

}

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

After this line:

var f= this.getField(this.getNthFieldName(i));

Add this:

if (f==null) continue;

TOPICS
Acrobat SDK and JavaScript, Macintosh, Windows

Views

94

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Error occurring on PC Adobe Reader 2017, but functioning on Mac Adobe Acrobat DC

Jun 26, 2019

Copy link to clipboard

Copied

I have pieced together Javascript to validate that required forms are filled, if filled, prompt a save as with new name suggestion, and then email submission. It functions properly on Mac Adobe Acrobat Pro DC, but on Windows 10 Adobe Reader 2017, I received on the Javascript debugger "TypeError: f is null 7:Field:Mouse Down"

I have it set on a submit button, Mouse Down, run a JavaScript. It may look pretty messy as I am very novice to this!

Any idea why this would be happening from the script below?

var emptyFields = [];

for (var i=0; i<this.numFields; i++) {

     var f= this.getField(this.getNthFieldName(i));

     if (f.type!="button" && f.required && f.display==display.visible) {

          if ((f.type=="text" && f.value=="" && f.value !== 0) || (f.type=="checkbox" && f.value=="Off")) emptyFields.push(f.name);

     }

}

    if (emptyFields.length>0) {

        app.alert("At least one required field was empty. Fill out the required fields before saving:\n" + emptyFields.join("\n"));

    } else {   

        var newFileName =

("TheFeed_DigitalContentBrief_") +

this.getField("Brand").valueAsString + "_" + this.getField("Market").valueAsString + "_" + this.getField("BriefingDate").valueAsString + ".pdf";

        app.response("Please copy the text below and use it as the new file-name:","", newFileName);

        app.execMenuItem("SaveAs");

this.mailDoc({bUI:false,cTo:"General - TEAMS: The Feed LATAM <042c8d45.nestle.onmicrosoft.com@emea.teams.ms>",cSubject:"New Content Brief from " + this.getField("Market").value + " for " + this.getField("Brand").value, cBody:"Attached new Digital Content Brief, please review."})

}

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

After this line:

var f= this.getField(this.getNthFieldName(i));

Add this:

if (f==null) continue;

TOPICS
Acrobat SDK and JavaScript, Macintosh, Windows

Views

95

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jun 26, 2019 0
Most Valuable Participant ,
Jun 27, 2019

Copy link to clipboard

Copied

After this line:

var f= this.getField(this.getNthFieldName(i));

Add this:

if (f==null) continue;

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 27, 2019 0
Jun 27, 2019

Copy link to clipboard

Copied

Thank you so much!! It now works to continue the process for saving and submitting, but doesn't give notice for fields required being unfilled. Is there another way you know of coding this function?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 27, 2019 0
Most Valuable Participant ,
Jun 27, 2019

Copy link to clipboard

Copied

This code should work (I wrote it...), but change this line:

if ((f.type=="text" && f.value=="" && f.value !== 0) || (f.type=="checkbox" && f.value=="Off"))

To:

if (f.valueAsString==f.defaultValue)

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 27, 2019 0
Jun 27, 2019

Copy link to clipboard

Copied

Yes, that worked! I have been referencing your code pieces I've found to put this together! Thank you so much for your expertise!

One last question! Is there a way to stop the next function if the user hits cancel on the save window instead of continuing to submission?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 27, 2019 0
Most Valuable Participant ,
Jun 27, 2019

Copy link to clipboard

Copied

Only if it's a part of the same script, not if it's a separate command.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 27, 2019 0
Jun 27, 2019

Copy link to clipboard

Copied

ok! Thank you for all of your help!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 27, 2019 0