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

Deleting pages with javascript

Explorer ,
Aug 19, 2020 Aug 19, 2020

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); 
}
TOPICS
PDF forms
4.5K
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 ,
Aug 31, 2020 Aug 31, 2020

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.

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
Community Expert ,
Aug 19, 2020 Aug 19, 2020

What pages want you delete?

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
Explorer ,
Aug 19, 2020 Aug 19, 2020

I want to delet page 13, 14 and 15

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 ,
Aug 19, 2020 Aug 19, 2020

OK

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
LEGEND ,
Aug 19, 2020 Aug 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?

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
Explorer ,
Aug 19, 2020 Aug 19, 2020

I want to delet page 13, 14 and 15. I added this code in AutoMailMerge to excute this 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 Expert ,
Aug 19, 2020 Aug 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?

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
Explorer ,
Aug 19, 2020 Aug 19, 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 

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 ,
Aug 20, 2020 Aug 20, 2020

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

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 ,
Aug 20, 2020 Aug 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.

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
Explorer ,
Aug 23, 2020 Aug 23, 2020

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

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 ,
Aug 23, 2020 Aug 23, 2020

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

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
Explorer ,
Aug 31, 2020 Aug 31, 2020

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.

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 ,
Aug 31, 2020 Aug 31, 2020

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.

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
Explorer ,
Aug 31, 2020 Aug 31, 2020
LATEST

WOOOOW! You saved my life. Thanks very much for your 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