The Why
If you’ve ever wanted to bulk delete all attachments from a task especially the pesky images from email signatures, here’s a script action you can use to create this rule.
Demo
Here’s the script running in action.
Screenshots
Run Script > Editor tab
Run Script > Run History tab
Run Script > Run History tab (script log)
Level of Difficulty: Beginner
It is extremely easy to set this up and you won’t need to be a developer for this. ![]()
Important Notes
- External Actions / Script Actions are only available on Enterprise and Enterprise+
- The script deletes ALL attachments
- Deleted attachments CANNOT be recovered
- When the script runs on a parent task, it only deletes attachments from the parent task and not any attachments from subtasks.
- To delete attachments from the subtasks, you can run the rule on the subtask manually.
Instructions
Here are the simple steps to set it up.
- Go to the project where you want to create this automation
- Select Customize > Rules
- Add a new rule > Start from scratch
- Give the rule a clear name e.g. [External Script Action] Delete All Attachments from Task
- Add a trigger for when rule is run manually and give it a label e.g. “Delete attachments”. My reason for keeping it manual is so I can choose where/when it runs. Otherwise you can always choose a different trigger that is more automated.
- Add an action > External Actions
- Copy-n-paste the code snippet below
- Save
- Make sure to test it on a dummy task with attachments to make sure the code is run successfully. You can view the Run History which is the tab on the right of the Editor
Code Snippet
const run = async () => {
// Step 1: Get all attachments for the triggered task
// NOTE: ‘parent’ must be passed as the first argument, not inside opts
const opts = {
opt_fields: “gid,name,resource_subtype”
};
const attachmentsResponse = await attachmentsApiInstance.getAttachmentsForObject(task_gid, opts);
const attachments = attachmentsResponse.data;
if (!attachments || attachments.length === 0) {
log(“No attachments found on this task. Nothing to delete!”);
return;
}
log(Found ${attachments.length} attachment(s). Starting deletion...);
// Step 2: Loop through and delete each attachment
for (const attachment of attachments) {
try {
await attachmentsApiInstance.deleteAttachment(attachment.gid);
log(Deleted: "${attachment.name}" (${attachment.gid}));
} catch (err) {
log(Failed to delete: "${attachment.name}" — ${JSON.stringify(err.response?.body || err)});
}
}
log(“All done! Attachment deletion complete.”);
};
run();


