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

Delete Attachement/Annotation based on description

Guest
Mar 03, 2016 Mar 03, 2016

I have two button to attached two different files and have coded it to show a specific description when viewing the properties. For this example lets say one is "dog" the other is "cat".

so that the end user does not have to go to the attachment pan and manually delete the file, I need a script that will only delete the file type with a description of "cat".

FYI Background.

Ap: Adobe Pro XI, I do not have Livecycle

I am already using a reset button to wipe the whole form, which works great. I have already coded that if a user selects an item from a drop down box, it makes the "cat" attachment button available, however if the user for what ever reason changes the drop down selection after attaching the "cat" file, the attachment remains and does not delete.  Since attachments are annotations versus object, what would be the script to just recognize if the file description is "cat", remove it - Then I will add it to my drop down box script.

Thanks!

TOPICS
Acrobat SDK and JavaScript , Windows
1.0K
Translate
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

LEGEND , Mar 03, 2016 Mar 03, 2016

So you must also have code that removes all attached files. You'd just have to modify it a bit so it looks at either the name or contents property and only removes those that indicate cat.

Translate
LEGEND ,
Mar 03, 2016 Mar 03, 2016

Exactly how are users attaching the files? If you're using a script in the cat and dog buttons, it would be helpful to see the scripts.

Translate
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
Guest
Mar 03, 2016 Mar 03, 2016

Thanks for replying George.  I am using 2 document level scripts provided in another discussion.  I need two because I need the description of each file to be unique regardless of the name the user attaches.  But I want the drop down box, lets call it "animal type" to control if the Cat attachment stays or goes.  The Dog Attachment should always remain until the user resets the whole form.  (no issues there it works).

function attach_11() {

try {

  var annot = addAnnot({
   page: event.target.page,
   type: "FileAttachment",
   author: "Submitter",
   name: "CAT",
   point: [oFAP.x, oFAP.y],
   contents: "CAT: ",
   attachIcon: "Paperclip"
  });

  annot.cAttachmentPath; // Prompt user to select a file to attach
 
 
} catch (e) {

  app.alert({
   cMsg: "No File Attached.\r\r",
   cTitle: "File attachment error",
   nIcon: 3,
   nType: 0
  });

}

}

Translate
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 ,
Mar 03, 2016 Mar 03, 2016

So you must also have code that removes all attached files. You'd just have to modify it a bit so it looks at either the name or contents property and only removes those that indicate cat.

Translate
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
Guest
Mar 03, 2016 Mar 03, 2016

Thanks, that is where I am getting hung up.  I can't seem to figure out the correct scripting to make it only recognize "cat".

Translate
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 ,
Mar 03, 2016 Mar 03, 2016

Can you show the code you're using to delete the attachments?

Translate
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
Guest
Mar 03, 2016 Mar 03, 2016

//Delete all attachments on form reset

this.syncAnnotScan();

var annots = this.getAnnots();

if (annots) {

    for (var i=annots.length-1; i>=0; i--) {

        annots.destroy();

    }

}

Translate
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 ,
Mar 03, 2016 Mar 03, 2016

OK, to delete just the CAT file attachments that were attached using the other code you showed, you could use something like:

//Delete all CAT attachments

this.syncAnnotScan();

var annots = this.getAnnots();

if (annots) {

    for (var i = annots.length - 1; i >= 0; i--) {

        if (annots.name === "CAT") {

            annots.destroy();

        }

    }

}

Translate
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
Guest
Mar 03, 2016 Mar 03, 2016
LATEST

wow George!  That is so simplistic its embarrassing for me!  Thank you.

Translate
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