Highlighted

Deleting pages with javascript

Explorer ,
Aug 19, 2020

Copy link to clipboard

Copied

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); 
}
Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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.

TOPICS
PDF forms

Views

125

Likes

Translate

Translate

Report

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

Deleting pages with javascript

Explorer ,
Aug 19, 2020

Copy link to clipboard

Copied

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); 
}
Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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.

TOPICS
PDF forms

Views

126

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Aug 19, 2020 0
Adobe Community Professional ,
Aug 19, 2020

Copy link to clipboard

Copied

What pages want you delete?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 19, 2020 0
Explorer ,
Aug 19, 2020

Copy link to clipboard

Copied

I want to delet page 13, 14 and 15

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 19, 2020 0
Adobe Community Professional ,
Aug 19, 2020

Copy link to clipboard

Copied

OK

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 19, 2020 0
Most Valuable Participant ,
Aug 19, 2020

Copy link to clipboard

Copied

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?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 19, 2020 0
Explorer ,
Aug 19, 2020

Copy link to clipboard

Copied

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

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 19, 2020 0
Most Valuable Participant ,
Aug 19, 2020

Copy link to clipboard

Copied

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?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 19, 2020 0
Explorer ,
Aug 19, 2020

Copy link to clipboard

Copied

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 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 19, 2020 0
Adobe Community Professional ,
Aug 20, 2020

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 20, 2020 0
Most Valuable Participant ,
Aug 20, 2020

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 20, 2020 1
Explorer ,
Aug 23, 2020

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 23, 2020 0
Most Valuable Participant ,
Aug 23, 2020

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 23, 2020 1
Explorer ,
Aug 31, 2020

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 31, 2020 0
Most Valuable Participant ,
Aug 31, 2020

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 31, 2020 1
Explorer ,
Aug 31, 2020

Copy link to clipboard

Copied

WOOOOW! You saved my life. Thanks very much for your time.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 31, 2020 0