Copy link to clipboard
Copied
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!
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
});
}
}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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".
Copy link to clipboard
Copied
Can you show the code you're using to delete the attachments?
Copy link to clipboard
Copied
//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();
}
}
Copy link to clipboard
Copied
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();
}
}
}
Copy link to clipboard
Copied
wow George! That is so simplistic its embarrassing for me! Thank you.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now