Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Desperate Newbie question......stopping script when error message is required

Community Beginner ,
Jan 25, 2023 Jan 25, 2023

Hi, this is my first try at scripting ever and i'm 90% there but just can't figure out the last piece of the puzzle.  Everything works except for 1 last thing.....

I have 10 radio buttons that require a value (yes or no)  if those fields are not complete when you select the button the error message shows up.  But when you click "ok" on the error message.  The script continues anyways.  How do I stop the script from continuing on to the next script if that error message shows up?  Here is what I have so far and I'm so close I can taste it!!!!!  Any help would be AMAZING!  Thanks

 

 

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.valueAsString==f.defaultValue) emptyFields.push(f.name);

}

}

if (emptyFields.length>0) {

app.alert("Please complete the following fields:\n" + emptyFields.join("\n"));

}

TOPICS
JavaScript
1.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
Jan 25, 2023 Jan 25, 2023

You forgot the else condition:

 

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.valueAsString==f.defaultValue) emptyFields.push(f.name);

}

}

if (emptyFields.length>0) {

app.alert("Please complete the following fields:\n" + emptyFields.join("\n"));
}

else {

var t = this.getTemplate("Permitpage1");

t.spawn(this.numPages, true, false);
var t = this.getTemplate("Permitpage2");

t.spawn(this.numPages, true, false);
var t = this.getTemplate("Permitpage3");

t.spawn(this.numPages, true, false);

}


Acrobate du PDF, InDesigner et Photoshopographe

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 25, 2023 Jan 25, 2023

And what is the next script and where is that script?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 25, 2023 Jan 25, 2023

The next script is to spawn the templates (shown below) but I have this in the next script.  (maybe I'm doing this wrong I have no idea, but its all working except this one thing)  So if the error button appears or you click ok I need it to not spawn the templates.  thanks!

 

var t = this.getTemplate("Permitpage1");

t.spawn(this.numPages, true, false);
var t = this.getTemplate("Permitpage2");

t.spawn(this.numPages, true, false);
var t = this.getTemplate("Permitpage3");

t.spawn(this.numPages, true, false);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 25, 2023 Jan 25, 2023

Are both scripts in the same place? If yes, put spawn script in 'else' after alert.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 25, 2023 Jan 25, 2023

You forgot the else condition:

 

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.valueAsString==f.defaultValue) emptyFields.push(f.name);

}

}

if (emptyFields.length>0) {

app.alert("Please complete the following fields:\n" + emptyFields.join("\n"));
}

else {

var t = this.getTemplate("Permitpage1");

t.spawn(this.numPages, true, false);
var t = this.getTemplate("Permitpage2");

t.spawn(this.numPages, true, false);
var t = this.getTemplate("Permitpage3");

t.spawn(this.numPages, true, false);

}


Acrobate du PDF, InDesigner et Photoshopographe
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 25, 2023 Jan 25, 2023

JR that works!!!!!  YAY!!!  Thanks so much!!!   That was 3 days of my life gone!!!

but one last question.....

If the user fills out form correctly and keeps clicking the button it keeps spawning more and more pages.  Is there a way to make it happen only once?  

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 25, 2023 Jan 25, 2023

You can check number of pages before spawning templates and only spawn if that number is correct.

For example lets say you have 2 pages, use this:

if(this.numPages == 2){

...script to spawn templates}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 25, 2023 Jan 25, 2023

Nesa, I'm a total newbie so I'm not completely sure where to put that?  I have 3 spawned pages and if the button is clicked (and fields are filled) I want all 3 pages to spawn everytime, but only 1 time.    

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 25, 2023 Jan 25, 2023

Here is the script with Nesa's enhancement:

 

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.valueAsString==f.defaultValue) emptyFields.push(f.name);

}

}

if (emptyFields.length>0) {

app.alert("Please complete the following fields:\n" + emptyFields.join("\n"));
}

else if (emptyFields.length == 0 && this.numPages == 2) {

var t = this.getTemplate("Permitpage1");

t.spawn(this.numPages, true, false);
var t = this.getTemplate("Permitpage2");

t.spawn(this.numPages, true, false);
var t = this.getTemplate("Permitpage3");

t.spawn(this.numPages, true, false);

}


Acrobate du PDF, InDesigner et Photoshopographe
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 25, 2023 Jan 25, 2023
LATEST

Thats it!!!!  Thank you guys so much!!!!!   I've spent HOURS on this and I actually found the end of the internet!!!  

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