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

NotAllowedError: removeField on Batch Sequence

Explorer ,
Jan 20, 2018 Jan 20, 2018

Copy link to clipboard

Copied

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!

TOPICS
Acrobat SDK and JavaScript

Views

1.6K

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
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 23, 2018 Jan 23, 2018

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?

Votes

Translate

Translate
LEGEND ,
Jan 20, 2018 Jan 20, 2018

Copy link to clipboard

Copied

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...?

Votes

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
community guidelines
Community Expert ,
Jan 20, 2018 Jan 20, 2018

Copy link to clipboard

Copied

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.

Votes

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
community guidelines
Explorer ,
Jan 20, 2018 Jan 20, 2018

Copy link to clipboard

Copied

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.

Votes

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
community guidelines
Community Expert ,
Jan 21, 2018 Jan 21, 2018

Copy link to clipboard

Copied

The script always returns "undefined" when the last thing executed doesn't return a value. "undefined" is just the default value for anything and everything that doesn't have a specific value;

To fix this you are going to have to do some debug.

Add some "console.println" statements to your code

// Put this one one top of the script

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

// Put these two lines in the loop that removes the fields, put them before the "removeField" call

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

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

Clear the console window and run the Action.

The idea is to nail down the problem field and to make sure it exists.

A general fix for handling the error is to put the offending code into a try/catch block, so at least the action can continue.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

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
community guidelines
Explorer ,
Jan 22, 2018 Jan 22, 2018

Copy link to clipboard

Copied

Thank you Thom! I have added those lines to my script and done some testing.

I continue to get the error on the last item of the array ("KRUT"). I removed KRUT from the end of the array and got the same result with the penultimate item, "KBUR".  I tried it entirely without the loop/array and can remove each field individually except for the last one.

I tried switching the loop so that it removes the last object first, and I get the error immediately (with no objects removed).

I must be missing a huge piece of the puzzle here. Or maybe a small one, but I am totally lost.

Votes

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
community guidelines
Community Expert ,
Jan 22, 2018 Jan 22, 2018

Copy link to clipboard

Copied

Did you try this on a document with this 9 fields only?

Votes

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
community guidelines
Explorer ,
Jan 22, 2018 Jan 22, 2018

Copy link to clipboard

Copied

I have tried it both ways. My test file is empty besides these 9 checkboxes, but I did try it with other test fields on the page to see if that was the issue, and I still got the error.

Votes

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
community guidelines
Community Expert ,
Jan 22, 2018 Jan 22, 2018

Copy link to clipboard

Copied

Did you create a new document with this 9 fields?

Votes

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
community guidelines
Explorer ,
Jan 22, 2018 Jan 22, 2018

Copy link to clipboard

Copied

No, I am only working with one open file.

Votes

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
community guidelines
Community Expert ,
Jan 22, 2018 Jan 22, 2018

Copy link to clipboard

Copied

Since this is only happening in Batch and not when you run the script from the console, and the type of error, it makes me think the meaning of "this" is changing. Is there anything else going on in the batch process? Are there more then one doc being processed? Are there other actions/scripts being run? Are there scripts on the fields?

And do this with Bernd's suggestion. Create a PDF with only these fields on it, and nothing else.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

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
community guidelines
Explorer ,
Jan 22, 2018 Jan 22, 2018

Copy link to clipboard

Copied

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!

Votes

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
community guidelines
Community Expert ,
Jan 22, 2018 Jan 22, 2018

Copy link to clipboard

Copied

How about if you change the name of the last box from "KRUT" to something else, "AAA" for example. Does it repeat the same behavior?

Is it always the last checkbox created? Regardless of name and of the number of items in the list?  What happens when you put a non-existent field name in the list? what error do you get?

Are these two separate commands in the sequence? What happens when the "add" script is run first from the console, and then only the "remove" script is in the batch sequence.  What about putting them together in the same command.

Maybe Acrobat is doing something funny like holding onto the memory of last field created. Try adding an "addField" at the bottom of the first script, just to create something. Try adding it to the top of the second script.  This will let us know if it's all about the last field created.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

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
community guidelines
Community Expert ,
Jan 23, 2018 Jan 23, 2018

Copy link to clipboard

Copied

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?

Votes

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
community guidelines
Explorer ,
Jan 23, 2018 Jan 23, 2018

Copy link to clipboard

Copied

Well, I suppose that would be my problem then! I have to say that doesn't make a lot of sense to me. I can understand disallowing the deletion of the last page, but the last field? I'm sure there's a reason for it, I'm just not seeing it.

The purpose of this sequence is to take a form that will be used for several different companies, add a header like the one below, create the checkbox fields for branch selection, save it with a prefix, then remove the header / checkbox fields and repeat the sequence for a different company (different header, different checkboxes). I will try a workaround by adding another hidden field and removing all but that one throughout the sequence.

CHECKBOX_HEADER_EXAMPLE.jpg

Thank you everyone for your help. I will let you know how it works out.

Votes

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
community guidelines
Community Expert ,
Jan 23, 2018 Jan 23, 2018

Copy link to clipboard

Copied

I must say I've never heard of or encountered such a limitation. It might be a bug, though.

Votes

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
community guidelines
Explorer ,
Jan 23, 2018 Jan 23, 2018

Copy link to clipboard

Copied

LATEST

It is strange right?

I have finally managed to get around this error by creating a hidden field and removing all fields but that one. I don't understand why but I guess it works!

Thanks so much to all who helped!

Votes

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
community guidelines
LEGEND ,
Jan 20, 2018 Jan 20, 2018

Copy link to clipboard

Copied

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

Votes

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
community guidelines