deleteAll attachment function in GlideSysAttachment() in scoped app not available
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2023 06:37 AM
hi guys, the below script:
var attachment = new GlideSysAttachment(); //Initialize GlideSysAttachment()
var grCase = new GlideRecord('sn_hr_core_case'); // GlideRecord along 'sn_hr_core_case' table
grCase.addEncodedQuery('numberSTARTSWITHHRC0001116');
grCase.query();
while (grCase.next()) {
attachment.deleteAll(grCase); //Deleting all attachments
}
Drops an error
Cannot find function deleteAll in object [object GlideSysAttachment].
The same script with 'incident' table works well. So I suppose this deleteAll function is not available from scoped app? Do you know any workaround if we still can use GlideSysAttachment() deleteAll in scope? Many thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2023 06:57 AM
Hi @rexter1
Instead of attachment.deleteAll(grCase), why don't you use deleteAttachment(string attachmentID)
Please mark correct if my response has solved your query.
Cheers,
Mohammed Basheer Ahmed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2023 05:41 AM
No, because for that we would need to know the sys_id of the attachment.First we need to know from what cases we need to delete attachments (closed befoe X time) then fo to attachment tabel to delete. We can clearly delete the records with two glide records, one on HR case, 2nd on attachment, but we cant use GlideSysAttachment(); deleteAll function, which would be much more better and clear.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2024 12:29 AM
Apparently attachment.deleteAll(gr) - is for Global, in scope it gives error as you mention.
to go around it use Global Script Include or Global Scheduled job,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2024 08:12 AM
Hi @rexter1 - I expect you could try something like this to achieve the same:
var grCase = new GlideRecord('sn_hr_core_case');
grCase.addEncodedQuery('numberSTARTSWITHHRC0001116');
grCase.query();
while (grCase.next()) {
var sysAttachment = new GlideSysAttachment();
var attachmentGR = sysAttachment.getAttachments(grCase.getTableName(), grCase.getValue('sys_id'));
while (attachmentGR.next()) {
sysAttachment.deleteAttachment(attachmentGR.getValue('sys_id'));
}
}