Skip to main content
Alliosaaa
Inspiring
January 20, 2018
Answered

NotAllowedError: removeField on Batch Sequence

  • January 20, 2018
  • 2 replies
  • 2924 views

I create forms for several different companies, and often the only difference is the header. Each header has several checkbox fields to select a particular branch for that company. To save time, I am working on a batch sequence to have the following functionality on one open file:

  1. *Add Background (this is the header, a pre-saved image)
  2. *Add Header/Footer (stamp with revision date)
  3. Add Checkbox Fields (via JS Execution)
  4. *Save Document with a prefix
  5. *Remove Old Background
  6. Remove Old Checkbox Fields (via JS)
  7. *Add New Background
  8. Add New Checkbox Fields (via JS)
  9. *Save Document with a prefix

*Lines marked with an asterisk are built into the action using pre-built action wizard tools... for now.

and so on... once I nail this down I will need it to go through about 5 iterations to end up with 5 saved files that have different headers. However, I am running into several problems.

  • First and foremost, the code to remove the first set of checkboxes works perfectly in the console. No errors and removes all checkboxes, however it does return "undefined".

/* remove old checkboxes */

var oldBoxes = ["KPOR", "KBAN", "KLEB", "KLIM", "KCON", "KNAS", "KPAT", "KBUR", "KRUT"];

     for (i = 0; i < oldBoxes.length; i++) {

          this.removeField(oldBoxes);

     }

When I try to execute the same code in the batch sequence, all but the last checkbox "KRUT" are removed, and I get a NotAllowedError:

NotAllowedError: Security settings prevent access to this property or method.

Doc.removeField:4:Batch undefined:Exec

I thought maybe this was due to the fact that the file was saved with a different name prior to removing fields, but removing the save function from the batch sequence produces the same result. Could the "undefined" that is returned when executed in the console have something to do with this?

  • Ultimately, I would like for each iteration of the sequence to "Save As" instead of just saving each file. How it currently works (saving with a prefix) means that the next prefix is added to the beginning of the last file name (i.e. PFIX2_PFIX1_MyDoc.pdf) and I want to avoid that. It would also be awesome if I could save the root file name with both a pre-programmed prefix and a suffix of a revision date (i.e. _01.20.18). I have no experience with saving documents via JS (but I learn quickly) so any advice to get me started would be greatly appreciated!

FYI I am using Acrobat Pro DC on Mac OS 10.13.1. I am the only one who will need to use this sequence on my own computer.

THANK YOU!

This topic has been closed for replies.
Correct answer Bernd Alheit

I had that thought as well. I tried changing "this" to "event.target" to see if it helped and unfortunately it did not. I've created a new blank test file (simply a blank page, no text, no fields, no scripts). For the purpose of solving this dilemma, I've removed all other steps of the action. I now only have 2 steps: adding checkbox fields and removing them.

  1. Create first set of checkbox fields - works like a charm, no errors.

var cBoxes     = ["KPOR", "KBAN", "KLEB", "KLIM", "KCON", "KNAS", "KPAT", "KBUR", "KRUT"];

var yLeft      = 703.1593017578125;

var yRight     = 688.2135620117188;

var xLeft      = 79.00044250488281;

var xRight     = 95.03680419921875;

for (i = 0; i < cBoxes.length; i++) {

     var name     = cBoxes;

     var type     = "checkbox";

     var page     = 0;

     var location = [xLeft, yLeft, xRight, yRight];

     var addcBoxes = this.addField(name, type, page, location);

     if (addcBoxes !== null) {

          addcBoxes.fillColor = color.white;

          addcBoxes.strokeColor = color.black;

     }

     xLeft  += 57.94297790527344;

     xRight += 57.94297790527344;

}

   

2. Remove first set of checkbox fields -  I have reversed the increment of the loop to start with the last object and move down to the first. With a positive increment it removes all but "KRUT", and with a negative increment it does not remove anything (NotAllowedError thrown on "KRUT"). Again, this code continues to work in the console but not in the batch sequence.

console.println("File:" + this.documentFileName);

var oldBoxes = ["KPOR", "KBAN", "KLEB", "KLIM", "KCON", "KNAS", "KPAT", "KBUR", "KRUT"];

var num      = oldBoxes.length;

for (i = num-1; i >= 0; i--) {

     console.println("Field:" + oldBoxes);

     console.println("obj:" + this.getField(oldBoxes));

     this.removeField(oldBoxes);

}

THANK YOU to everyone who has helped so far. I can export the action and share it if that would help!


Acrobat doesn't allow the remove of the last created field.

Why did you create the fields when you remove this fields in the next step?

2 replies

Legend
January 20, 2018

You are right, of course Bernd. My apologies, JoeAlosa.

Legend
January 20, 2018

Your code has the most common bug for deleting multiple elements. Have you considered that after you remove oldBoxes[0], that all the other entries shuffle down, so the entry formerly at oldBoxes[1] is now at oldBoxes[0], where it will stay...?

Bernd Alheit
Community Expert
Community Expert
January 20, 2018

https://forums.adobe.com/people/Test+Screen+Name  wrote

Your code has the most common bug for deleting multiple elements. Have you considered that after you remove oldBoxes[0], that all the other entries shuffle down, so the entry formerly at oldBoxes[1] is now at oldBoxes[0], where it will stay...?

oldBoxes is an array with field names. removeField will not change this array.

Alliosaaa
AlliosaaaAuthor
Inspiring
January 20, 2018

Thank you both for your replies! I am still a bit confused. Am I getting the error because I've removed the fields but the array still exists? If so, should I pop each value out prior to removing it? I'm also curious as to why the code works in the console but not in the batch sequence.