Skip to main content
Participating Frequently
August 19, 2020
Answered

Deleting pages with javascript

  • August 19, 2020
  • 4 replies
  • 5050 views

I want to delete pages if value is 0, but it delet another pages and only one page, there is somthing that I don't understand

var fx5 = this.getField("avgCbitq5");
var fx6 = this.getField("avgCbitq6"); 
var fx7 = this.getField("avgCbitq7");

if (fx5.value == "0"){
this.deletePages(12); 
}

else if (fx6.value == "0"){
this.deletePages(13); 
}

else if (fx7.value == "0"){
this.deletePages(14); 
}
This topic has been closed for replies.
Correct answer try67

Okay : ) simply I need a script to check filed value, if this value == 0 then delete this page. I want to repeat it to all pages.
For example: page#1 contains fieldA if it's value equals to 0 then delete it, then in page#2 if fieldB value equals to 1 then don't delete it. I have 18 pages each page contains different fields.


You can do it like this:

 

if (this.getField("fieldA").valueAsString=="0") this.deletePages(this.getField("fieldA").page);

if (this.getField("fieldB").valueAsString=="0") this.deletePages(this.getField("fieldB").page);

etc.

 

That way you're not using the actual page numbers, but the ones the fields are on, so you don't need to do it in reverse or hard-code the numbers into your code.

4 replies

try67
Community Expert
Community Expert
August 20, 2020

If you want to delete all three pages then you should do it either in a single command, or in reverse order, because when you delete page 13 what was before page 14 is now page 13, not 14, and the same for all other pages that follow it.

Participating Frequently
August 23, 2020

I lattely tried to do it but it's not working at all

try67
Community Expert
Community Expert
August 23, 2020

You need to provide more information if you want help...

try67
Community Expert
Community Expert
August 19, 2020

What's your question, then? Your code does that. Does it not work correctly? If so, what happens when you use it?

Also, where did you place it?

Participating Frequently
August 20, 2020

I want to delet page 13, 14 and 15. I added this code in AutoMailMerge to excute this script at the end. But it delets only one page page#(14). I know that pages start's at #Zero in the code. 
What I want is to delete pages if a certian value is 0 but it didn't work at all as I want. 

 

In this scenario it should delete 3 pages but it didn't work.  

Executed PDF 

Bernd Alheit
Community Expert
Community Expert
August 20, 2020

The document doesn't have any form field. Where does you use your script? Why does you use a if-else structure?

Legend
August 19, 2020

Hmm, I'd expect this to delete one of pages 13 or 14 or 15 

or two of 13,16 or 14,16 or 13,15

or all three of 13,15,17

I didn't carefully check. Is that really what you want?

Participating Frequently
August 20, 2020

I want to delet page 13, 14 and 15. I added this code in AutoMailMerge to excute this script.

 
Bernd Alheit
Community Expert
Community Expert
August 19, 2020

What pages want you delete?

Participating Frequently
August 20, 2020

I want to delet page 13, 14 and 15

Bernd Alheit
Community Expert
Community Expert
August 20, 2020

OK