- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-12-2014 07:07 AM
Is it possible to remove attachments by using GlideSysAttachment? I'm looking for a function similar to GlideSysAttachment.copy(...), something like GlideSysAttachment.remove(...) or GlideSysAttachment.delete(...). If there is such a function where is it documented?
Solved! Go to Solution.
- 27,873 Views

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2014 08:56 AM
If you want to remove all attachments from the record, you can use the following where recordGR is the gliderecord representing the record from which you want to remove attachments.
var attach = new GlideSysAttachment();
attach.deleteAll(recordGR);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-19-2016 07:40 AM
I'm using this in a Business Rule, on the sysapproval_approver table. So not on a scoped app, no.
No worries though, as my solution (work-around) is working great.
I just wasn't understanding why Brad's solution was throwing an error for me.
Thanks for your reply though!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2018 08:21 AM
Hi Brad. What is exactly the recordGR? The sys_id of the request where the documents had been attached?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2014 12:03 AM
Thank you! deleteAttachment(...) and deleteAll(...) are the functions I was looking for.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2014 03:49 PM
Jan,
For the benefit of future searchers (aka me!), would you mind marking Brad's post as the answer?
Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2020 03:52 PM
Anyone stumbling across this today will find deleteAll does not work on the scoped version of GlideSysAttachment - and going straight to the sys_attachment table has issues with cross-scope policy / application access.
You can just use deleteAttachment in the scoped version of GlideSysAttachment, like so:
function deleteAllAttachments(record){
// Utility function removes all the previous attachments
// Must use GlideSysAttachment in scope
var gsa = new GlideSysAttachment();
var att = new GlideRecord('sys_attachment');
att.addQuery('table_name',record.getTableName());
att.addQuery("table_sys_id",record.sys_id);
att.query();
while(att.next()){
gsa.deleteAttachment(att.sys_id);
}
}
I believe this should also respect whether your current scope can access the table your attachments are attached to, which is important, and keeps security tight on your sys_attachment table.