Expand my Community achievements bar.

Script to delete all attachments

Avatar

Former Community Member
Hi all



I was wondering whether there is a script to delete all of the attachments in a pdf form? I know that you can use removeDataObject to delete specific attachments by name, but was wondering whether there was a simple way to delete all of the attachments in one hit?



Cheers



Mark
2 Replies

Avatar

Level 5
You just need to loop through the dataObject.



// DUMP ANY ATTACHMENTS

var d = event.target.dataObjects;

if (d != null)

for (var i = 0; i < d.length; i++)

{

// console.println("Data Object[" + i + "]=" + d[i].name);

event.target.removeDataObject(d[i].name);

}

Avatar

Level 5

This script works great, but you need to remove the comment slashes on the console.println line, as below.  Thanks to the original poster.


var d = event.target.dataObjects;


if (d != null)


for (var i = 0; i < d.length; i++) {


     console.println("Data Object[" + i + "]=" + d[i].name);


     event.target.removeDataObject(d[i].name);


}