NotAllowedError: removeField action on button mouse-up

Contributor ,
Mar 23, 2017

Copy link to clipboard

Copied

Is this.removeField or something else in the below script a trusted function?

I'm trying to create a button that will delete fields by type. I want the button to delete buttons, checkboxes, and radio buttons.

I already have this as an action and it works, but I'd like it as a button for easy access and for other users to use.

I'm getting the following error: NotAllowedError: Security settings prevent access to this property or method. Doc.removeField:11:AcroForm:MouseUp:Action1

Below is the script I've modified from another forum, but can't seem to find the link to reference. The only difference is I added the or operand to find multiple field types. It's set to a mouse-up event. I've also tried putting most of it document level except for the last for condition and the delete button action., but that still produces the error. Additionally, I tried this.removeField with a named field and it works. I guess I'm not seeing anything that would require a trusted function...

//Remove Buttons and Checkboxes

var fields = new Array();
for ( var i=0; i<this.numFields; i++)
{
var fname = this.getNthFieldName(i);
if ((this.getField(fname).type == "button" || this.getField(fname).type == "checkbox" || this.getField(fname).type == "radiobutton"))
{
fields.push(fname);
}
}

for (var i=0; i<fields.length; i++)
{
this.removeField(fields);
}

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

Not for saving filled-in forms, but it does require it for executing some JS commands.

So this is happening when you run the code in Acrobat, from a button? Could it be that you're trying to delete the button that triggered this code? That would be a problem, as it's still being used at that moment.

TOPICS
Acrobat SDK and JavaScript, Windows

Views

1.3K

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

NotAllowedError: removeField action on button mouse-up

Contributor ,
Mar 23, 2017

Copy link to clipboard

Copied

Is this.removeField or something else in the below script a trusted function?

I'm trying to create a button that will delete fields by type. I want the button to delete buttons, checkboxes, and radio buttons.

I already have this as an action and it works, but I'd like it as a button for easy access and for other users to use.

I'm getting the following error: NotAllowedError: Security settings prevent access to this property or method. Doc.removeField:11:AcroForm:MouseUp:Action1

Below is the script I've modified from another forum, but can't seem to find the link to reference. The only difference is I added the or operand to find multiple field types. It's set to a mouse-up event. I've also tried putting most of it document level except for the last for condition and the delete button action., but that still produces the error. Additionally, I tried this.removeField with a named field and it works. I guess I'm not seeing anything that would require a trusted function...

//Remove Buttons and Checkboxes

var fields = new Array();
for ( var i=0; i<this.numFields; i++)
{
var fname = this.getNthFieldName(i);
if ((this.getField(fname).type == "button" || this.getField(fname).type == "checkbox" || this.getField(fname).type == "radiobutton"))
{
fields.push(fname);
}
}

for (var i=0; i<fields.length; i++)
{
this.removeField(fields);
}

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

Not for saving filled-in forms, but it does require it for executing some JS commands.

So this is happening when you run the code in Acrobat, from a button? Could it be that you're trying to delete the button that triggered this code? That would be a problem, as it's still being used at that moment.

TOPICS
Acrobat SDK and JavaScript, Windows

Views

1.3K

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
Mar 23, 2017 0
Contributor ,
Mar 23, 2017

Copy link to clipboard

Copied

Update: it seems to be doing part of the function and then stopping with the error. I tried another version with only deleting buttons and it deleted some but not others.

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...
Mar 23, 2017 0
Most Valuable Participant ,
Mar 23, 2017

Copy link to clipboard

Copied

- No, you don't need a trusted function to run this code. However, if you want to use it in Reader then the file must have Form Usage Rights applied to it. Are you running this code in Reader?

- Yes, when an error is encountered (and not caught) the script will stop executing immediately.

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...
Mar 23, 2017 0
Contributor ,
Mar 23, 2017

Copy link to clipboard

Copied

I'm running Acrobat Pro DC.

It's strange that the code works in an Acrobat Action but seems to produce an error when ran via mouse-up.

There are several fields with the same name for text field duplication and to keep the file lighter and less complicated.

On a side note, I was under the impression that Reader DC no longer needed usage rights enabled...

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...
Mar 23, 2017 0
Most Valuable Participant ,
Mar 23, 2017

Copy link to clipboard

Copied

Not for saving filled-in forms, but it does require it for executing some JS commands.

So this is happening when you run the code in Acrobat, from a button? Could it be that you're trying to delete the button that triggered this code? That would be a problem, as it's still being used at that moment.

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...
Mar 23, 2017 0
Contributor ,
Mar 23, 2017

Copy link to clipboard

Copied

The code is to remove all buttons, checkboxes, and radio buttons so it would delete the button that triggers it. Is there a way to exclude a named field?

I removed this.getField(fname).type == "button" from the if statement and the script ran without errors.

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...
Mar 23, 2017 0
Most Valuable Participant ,
Mar 23, 2017

Copy link to clipboard

Copied

Add this to your if-condition:

(fname!=event.target.name)

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...
Mar 23, 2017 0
Adobe Community Professional ,
Mar 24, 2017

Copy link to clipboard

Copied

MADink_Designs27  wrote

...

On a side note, I was under the impression that Reader DC no longer needed usage rights enabled...

Form rights and document save rights are not the same.

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...
Mar 24, 2017 1
Contributor ,
Mar 24, 2017

Copy link to clipboard

Copied

Works perfect! I was thinking something with the not operand. I assumed you were implying to add it to the button condition with the and operand so it reads if it's not THIS button and it's A button, delete it.

//Remove Buttons and Checkboxes
var fields = new Array();
for ( var i=0; i<this.numFields; i++)
{
var fname = this.getNthFieldName(i);
if ((fname!=event.target.name && this.getField(fname).type == "button" || this.getField(fname).type == "checkbox" || this.getField(fname).type == "radiobutton"))
  {
  fields.push(fname);
  }
}

for (var i=0; i<fields.length; i++)
{
this.removeField(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...
Mar 24, 2017 0
Contributor ,
Mar 24, 2017

Copy link to clipboard

Copied

Maybe I spoke too soon. It works in the page template, but once I hide the page template and run it the way I intend to, it's producing the error again. I'm going to try renaming field values on the spawn event as currently it's set to not rename and overlay over the first page.

You've commented on another forum regarding exporting data as FDF. Both of these are for the same project. What I'm trying to do is spawn a page template, with Import and Export buttons on it, from a button that will overlay on the first page outside the page margins as the template is 14" wide. The import button imports FDF and the Export will delete all buttons, checkboxes, and radio buttons, then perform the export process. Since this is a destructive action, I have the delete and export set to run only if the user clicks yes on the app alert.

The reason the buttons need to be deleted is the form was created in InDesign and sometimes InDesign and Acrobat don't love each other and other field types will remove the graphics from the InDesign buttons. The solution to this is to remove everything but the text fields. That way, the saved FDF is only the text field data.

Below it the full code:

Spawn Page Template—Run on Mouse-Up:

var imPort = this.getField("import");
var exPort = this.getField("export");
var imex = this.getTemplate("imex");

//spawn page
imex.spawn(0, false, true);

//show buttons
imPort.display = display.noPrint;
exPort.display = display.noPrint;

//focus page 1
this.pageNum = 0;

Export Button—Run on Mouse-Up:

//App Alert
var cBreak = "\n\n";
var cMsg = "Continuing with this action will DELETE all buttons, checkboxes, and radio buttons leaving only text fields. If you need to save or have other edting requirements with this document, please click No."
cMsg += "\n\nDo you wish to continue? If yes, DO NOT save this document after this action processes!";

var nXport = app.alert(cMsg,1,2,"Continue at Your Own Risk!");

if(nXport == 4) {

//Remove Buttons and Checkboxes
var fields = new Array();
for ( var i=0; i<this.numFields; i++)
{
var fname = this.getNthFieldName(i);
if ((fname!=this.event.target.name && this.getField(fname).type == "button" || this.getField(fname).type == "checkbox" || this.getField(fname).type == "radiobutton"))
  {
  fields.push(fname);
  }
}

for (var i=0; i<fields.length; i++)
{
this.removeField(fields);
}
//Export FDF
this.exportAsFDF({bAllFields:true});
}

var exPort = this.getField("export");

exPort.display = display.hidden;

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...
Mar 24, 2017 0
Contributor ,
Mar 24, 2017

Copy link to clipboard

Copied

Even with changing the spawn event to true, true to both rename fields and overlay, the operation is failing. The error I'm getting with this is GeneralError: Operation failed.

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...
Mar 24, 2017 0
Contributor ,
Mar 24, 2017

Copy link to clipboard

Copied

Assuming it had something to do with the page template, the code worked. I show the template before the delete buttons event then hide it again.

Sadly I went with a less sophisticated route to include users with Reader only and ditched the page template altogether. It's for internal use only, so I don't mind but it would have been nice to utilize the original script. The data is "submitted" to a blank mailto: where the user can just save the file from the new email that opens up.

Anyway, here's the Acrobat code that worked:

//App Alert
var cBreak = "\n\n";
var cMsg = "Continuing with this action will DELETE all buttons, checkboxes, and radio buttons leaving only text fields. If you need to save or have other edting requirements with this document, please click No."
cMsg += "\n\nDo you wish to continue? If yes, DO NOT save this document after this action processes!";

var nXport = app.alert(cMsg,1,2,"Continue at Your Own Risk!");

if(nXport == 4) {

  //Show Template
var imex = this.getTemplate("imex");
imex.hidden = false;

//Remove Buttons and Checkboxes
var fields = new Array();
for ( var i=0; i<this.numFields; i++)
{
var fname = this.getNthFieldName(i);
if (((fname!=this.event.target.name) && this.getField(fname).type == "button" || this.getField(fname).type == "checkbox" || this.getField(fname).type == "radiobutton"))
  {
  fields.push(fname);
  }
}

for (var i=0; i<fields.length; i++)
{
this.removeField(fields);
}
//Export FDF
this.exportAsFDF({bAllFields:true});

}

//Hide Export Button
event.target.name.display = display.hidden;

//Hide Template
imex.hidden = true;

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...
Mar 24, 2017 0
Oct 31, 2019

Copy link to clipboard

Copied

I used the same code (this.removeField(fields);) in my Javascript which was attached to a Button, and yes I was removing that same Button.  In Adobe Acrobat Pro 9 my Javascript worked fine; that Button was removed.  However when I upgraded to Pro DC then I got that same error message.  For the last week I was trying to figure out how I could change my security settings to eliminate that error.

 

When I read this post I realized I did not have to remove the Button field, just make them hidden.  My goal is to flatten all the form fields and eliminate all the Button fields.  When I  changed the code to f.display = display.hidden;, my Javascript worked in Pro DC.  Once I flattened the document the Button fields were completely gone.

I still think there must be a way to change the security settings so that I could remove the field with Javascript.  It still works fine in Acrobat 9 Pro.   This is why I have some hesitation when it comes to upgrading. 

I hope that my other Javascripts will continue to work without and debugging.

Thanks for this Post

 

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...
Oct 31, 2019 0
Adobe Community Professional ,
Oct 31, 2019

Copy link to clipboard

Copied

What happens when you use the code in the console?

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...
Oct 31, 2019 0
try67 LATEST
Most Valuable Participant ,
Oct 31, 2019

Copy link to clipboard

Copied

You have to test your code very carefully. There have been some changes to the permissions of various methods between Acrobat 9 and DC. Many of the methods that could be used from a doc-level script in the past now require a "privileged context" to work. In addition there are several bugs in Acrobat DC that prevent various scripts from working correctly.

 

By the way, I tried removing a button using its own Mouse Up event in Acrobat XI and it worked just fine, so I would say this new "feature" was introduced in the DC version.

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...
Oct 31, 2019 0