Skip to main content
Known Participant
August 5, 2024
Question

Remove spawned page

  • August 5, 2024
  • 1 reply
  • 516 views

Hello! I have the code below and it works to populate the page I'm needing called, Users 5 & 6, when the checkbox is marked. However, I'm trying to make it so if the box is unchecked it will then remove that page. It's not working for the removal...

 

var fld = this.getField("Users 5 & 6");
var ident;
if (fld.value=="On") {
// check to see if there is already a Users 5 & 6 Page
// if there is, don't add it again
var text = "";
var pages = new Array();

for (var i = 0; i < this.numFields; i++) {
if (this.getNthFieldName(i).indexOf("Identity") > -1 ) {
text += "Field[" + i + "] = " + this.getNthFieldName(i);

ident = this.getField(this.getNthFieldName(i));

text += " Page# " + ident.page + "#";
text += " hello " + ident.valueAsString;

if (ident.valueAsString == "Users 5 & 6") {
if (ident.page > -1) {
pages.push(ident.page); }
}
}
}

if (pages.length > 0) {
//remove // in front of app.alert for troubleshooting
//app.alert("already added");
}
else {
var temp = this.getTemplate("Users 5 & 6");

temp.spawn({nPage: this.numPages - 1, bOverlay: false});
}
//remove // in front of app.alert for troubleshooting
//app.alert(text,3);
//remove // in front of app.alert for troubleshooting
//app.alert("leave on");
}
else {
var text = "";
var pages = new Array();

for (var i = 0; i < this.numFields; i++) {
if (this.getNthFieldName(i).indexOf("Identity") > -1 ) {
text += "Field[" + i + "] = " + this.getNthFieldName(i);

ident = this.getField(this.getNthFieldName(i));

text += " Page# " + ident.page + "#";
text += " hello " + ident.valueAsString;

if (ident.valueAsString == "Users 5 & 6") {
if (ident.page > -1) {
pages.push(ident.page); }
}
}
}

for (var p = this.numPages - 1; p > -1; p--) {
if (pages.indexOf(p) > -1) {
//remove // in front of app.alert for troubleshooting
//app.alert(p);
this.deletePages(p);
}
}
//remove // in front of app.alert for troubleshooting
//app.alert(text,3);
//remove // in front of app.alert for troubleshooting
//app.alert("leave off");
}
this.calculateNow();

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
August 5, 2024

Check the values in the pages array before trying to delete those pages.

Known Participant
August 6, 2024

I'm so new to this. What does it mean to "check the values in the pages array"?

try67
Community Expert
Community Expert
August 6, 2024

Print them out to the console, to make sure they are what you think they are, like this:

console.println(pages.join(","));