Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Script to delete all attachments

Avatar

Not applicable
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);


}