11 Replies Latest reply on Mar 24, 2017 8:24 AM by MADink_Designs27

    NotAllowedError: removeField action on button mouse-up

    MADink_Designs27 Level 1

      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[i]);
      } 
      
        • 1. Re: NotAllowedError: removeField action on button mouse-up
          MADink_Designs27 Level 1

          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.

          • 2. Re: NotAllowedError: removeField action on button mouse-up
            try67 MVP & Adobe Community Professional

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

            • 3. Re: NotAllowedError: removeField action on button mouse-up
              MADink_Designs27 Level 1

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

              • 4. Re: NotAllowedError: removeField action on button mouse-up
                try67 MVP & Adobe Community Professional

                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.

                • 5. Re: NotAllowedError: removeField action on button mouse-up
                  MADink_Designs27 Level 1

                  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.

                  • 6. Re: NotAllowedError: removeField action on button mouse-up
                    try67 MVP & Adobe Community Professional

                    Add this to your if-condition:

                     

                    (fname!=event.target.name)

                    • 7. Re: NotAllowedError: removeField action on button mouse-up
                      Bernd Alheit Adobe Community Professional & MVP

                      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.

                      • 8. Re: NotAllowedError: removeField action on button mouse-up
                        MADink_Designs27 Level 1

                        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[i]);
                         }
                        
                        • 9. Re: NotAllowedError: removeField action on button mouse-up
                          MADink_Designs27 Level 1

                          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[i]);
                           } 
                           //Export FDF
                           this.exportAsFDF({bAllFields:true});
                          }
                          var exPort = this.getField("export");
                          exPort.display = display.hidden;
                          
                          • 10. Re: NotAllowedError: removeField action on button mouse-up
                            MADink_Designs27 Level 1

                            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.

                            • 11. Re: NotAllowedError: removeField action on button mouse-up
                              MADink_Designs27 Level 1

                              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[i]);
                               }
                               //Export FDF
                               this.exportAsFDF({bAllFields:true});
                              }
                              //Hide Export Button
                              event.target.name.display = display.hidden;
                              //Hide Template
                              imex.hidden = true;