9 Replies Latest reply on Jan 31, 2016 12:01 PM by tracyy42935226

    Please help Creating a Detach Button that detaches a document I have attached with an Attach Button

    tracyy42935226

      Let me apologize up front for this being a bit of complicated question. I found a thread on this forum that helped me attach a file with a click of a button- now I want to detach this same file.  Below is how far I've gotten.   

       

      I created a form in Adobe Acrobat DC that allows a user to attach a document to the form with a click of a button.  The way this is programmed is that on the button itself with a Mouse Up action, the following Javascript is run:

       

       

      if (app.viewerVersion < 11) {

          import_pre_11();

      } else {

          import_11();

      }

       

      Then there is a document level javascript for attaching the file that is programmed like this:

       

      // Initialize attachment number

      attachment_num = 1;

       

      // Initial location of file attachment icon

      // The x value is incremented below

      var oFAP = {x_init: -72, x: -72, y: -72};  // Below lower-left corner of the page

       

      function import_pre_11() {

       

          if (app.viewerType === "Reader") {

       

              app.alert({

                  cMsg: "You must user Reader version 11 or later to attach files to this form.",

                  cTitle: "Attach File Error",

                  nIcon: 3,

                  nType: 0

              });

         

              return;

          }

       

          // Prompt user to import a file

          app.alert({

              cMsg: "Click the OK button to select a file from your system.",

              cTitle: "Attach File",

              nIcon: 3,

              nType: 0

          });

         

          try {

         

              var rc = this.importDataObject("Attachment" + attachment_num);

              if (rc) {

                  attachment_num += 1;

                  app.alert({

                      cMsg: "Attachment successful.\r\rOpen the Attachments panel to access the attached file(s).",

                      cTitle: "Attachment Successful",

                      nIcon: 3,

                      nType: 0

                  });

                 

              } else {

                  app.alert({

                      cMsg: "Attachment cancelled.",

                      cTitle: "Attachment Cancelled",

                      nIcon: 3,

                      nType: 0

                  });

              }

             

             

          } catch (e) {

              app.alert({

                  cMsg: "Could not attach file.",

                  cTitle: "Could not attach file",

                  nIcon: 3,

                  nType: 0

              });

          }

       

      }

       

      function import_11() {

       

          try {

       

              var annot = addAnnot({

                  page: event.target.page,

                  type: "FileAttachment",

                  author: "Form user",

                  name: "File Attachment",

                  point: [oFAP.x, oFAP.y],

                  contents: "File attachment on: " + util.printd("yyyy/mm/dd HH:MM:ss", new Date()),

                  attachIcon: "Paperclip"

              });

       

              annot.cAttachmentPath; // Prompt user to select a file to attach

             

              oFAP.x += 18;  // Increment the x location for the icon

             

             

          } catch (e) {

       

              app.alert({

                  cMsg: "Could not attach file.\r\rPlease report this error.",

                  cTitle: "File attachment error",

                  nIcon: 3,

                  nType: 0

              });

       

          }

         

      }

       

       

      That process works flawlessly.  What I want to do now is detach that same document with the click of another button.  I understand very basic javascript but had help from the forum creating the above script.  Can anyone provide me a solution (if there is one), to help me detach the file that the user attached with the script above? Thank you so much in advance!!!