Delete sys_attachement record via script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2023 08:35 AM
I have a script in a privately scoped application that is supposed to delete a specific record from the sys_attachemt table, but for whatever reason it is not working. I confirmed that I have the proper cross-scope privileges to delete from the table, and the logs are showing the "INSIDE DELETE' message. The only issue is that it is not deleting the record.
Script:
var attachment = new GlideRecord("sys_attachment");
attachment.addQuery("table_nameLIKEsys_data_source^table_sys_id=bfa85545db6c3110663e633fd3961979");
attachment.query();
if(attachment.next()){
gs.info("INSIDE DELETE");
attachment.deleteRecord();
}
Logs:
Cross-Scope Privileges:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2023 11:09 PM
Hi @JJG_SNOW , as attachment are more complexe and splitted in different tables I recommend to use the Attachment API to delete attachments. Try the deleteAttachment function of GlideSysAttachment.
Greets
Daniel
Please mark reply as Helpful/Correct, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2023 11:19 PM
Can youOpen the table of "sys_attachment" check "can delete" checkbox and try again!
I have tried in my PDI and it worked!!
If my answer solved your issue, please mark my answer as ✅ Correct & 👍Helpful based on the Impact.