Copy link to clipboard
Copied
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"));
}
Copy link to clipboard
Copied
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);
}
Copy link to clipboard
Copied
And what is the next script and where is that script?
Copy link to clipboard
Copied
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);
Copy link to clipboard
Copied
Are both scripts in the same place? If yes, put spawn script in 'else' after alert.
Copy link to clipboard
Copied
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);
}
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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);
}
Copy link to clipboard
Copied
Thats it!!!! Thank you guys so much!!!!! I've spent HOURS on this and I actually found the end of the internet!!!
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more