Skip to main content
Psiomicron
Participant
April 30, 2026
Question

After deleting a spawned template with multiple pages, searching for a fieldname shows it on a page number that it existed on before.

  • April 30, 2026
  • 5 replies
  • 95 views

I have a form with checkboxes that will create templates in the form to fill out. I would like to uncheck the box and have it delete that particular form. I do this now by searching for a certain fieldname on that page. If it finds it, delete the page. This is my issue:

Say I have form 1 (page1), 2 (page2), 3 (page3) created. I remove 2. It removes and now there is form 1 (page1), and form 3 (now page2). When I try to delete form 3 now it searches for the specific fieldname, but it tells me that the field name is still on page 3, and thus can’t delete a page that is nonexistent, leaving form 3 (page2) still there. 

How do I get it to refresh (I have used “this.calculateNow();” before AND after deletion but dosen’t work) so it sees the fieldname on the proper page, ie page 2.

Here is my code:

if (trackerField != null) {

        this.calculateNow();
        var trackerField = this.getField("PageTracker2_" + cbName);
        var pageToDelete = Number(trackerField.value);
        
        // Remove the tracker field
        this.removeField("PageTracker2_" + cbName);

       //Let me know what page the tracker is on
        app.alert("On page " + pageToDelete, 3)
        // Delete the page
        this.deletePages(pageToDelete);
        this.calculateNow();

        }
 

Thanks!

 

    5 replies

    try67
    Community Expert
    Community Expert
    May 2, 2026

    Are you aware that page numbers are zero-based in JavaScript, meaning that if you tell deletePages to remove page “2” it will actually remove the third page in the file, not the second one. Also, you’re using the field’s value, not the page property. Is that on purpose?

    Thom Parker
    Community Expert
    Community Expert
    May 1, 2026

    Bernd has the right question. How is the value of the field “PageTracker2_XX” set?  And what is CBName?  Seems like you have some wires crossed in the scripting. 

     

    Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
    PDF Automation Station
    Community Expert
    Community Expert
    May 1, 2026

    If you have form fields on hidden template pages that are shown by spawning them, and then deleted, it is the spawned page that gets deleted.  The original page (hidden template) still exists as well as its form field.  The JavaScript page numbering will always return the visible pages only.  When spawning, if bRename is set to true, the field will exist on a hidden page.  If bRename is set to false, there will be 2 widgets of the same field and calling the page number of that field will return an array of page numbers. How are you getting the page number value into trackerField?

    TᴀW
    Legend
    May 1, 2026

    If worst comes to the worst, you could keep track internally of which form is on which (real) page.

    id-extras.com | InDesign tools & scripts for typesetters, form designers, and translators
    Bernd Alheit
    Community Expert
    Community Expert
    May 1, 2026

    How does you change the value of the trackerField?