Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2023 10:25 AM
I have followed the code for several solutions provided in these forums without success.
I am running this from a scoped app but I have checked the Can Delete checkbox on the Attachment table for All Application Scopes.
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id', ''); //The sys_id is between the quotes but redacted
gr.query();
while(gr.next()){
gs.info('Found attachment'); //This one does print
gs.info('Can Delete Attachment :' + gr.canDelete()); //This one gives me true
gs.info('File Name to be Deleted ' + gr.file_name); //This one gives me the proper file name
gr.deleteRecord(); //This one does not work and actually returns a value of false
}
I have also tried gr.deleteMultiple() and tried it in an if statement rather than a while. No luck. It must be permissions since it's finding the attachments but the ACLs and the cross scope potential issue has been remediated. Any assistance?
Solved! Go to Solution.
1 ACCEPTED SOLUTION
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2023 11:14 AM
You can update your script to like this
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id', ''); //The sys_id is between the quotes but redacted
gr.query();
while(gr.next()){
gs.info('Found attachment'); //This one does print
gs.info('Can Delete Attachment :' + gr.canDelete()); //This one gives me true
gs.info('File Name to be Deleted ' + gr.file_name); //This one gives me the proper file name
if(gr.canDelete()){
var attachmentSysID = gr.sys_id;
var attachment = new GlideSysAttachment();
attachment.deleteAttachment(attachmentSysID);
}
}
2 REPLIES 2
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2023 11:14 AM
You can update your script to like this
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id', ''); //The sys_id is between the quotes but redacted
gr.query();
while(gr.next()){
gs.info('Found attachment'); //This one does print
gs.info('Can Delete Attachment :' + gr.canDelete()); //This one gives me true
gs.info('File Name to be Deleted ' + gr.file_name); //This one gives me the proper file name
if(gr.canDelete()){
var attachmentSysID = gr.sys_id;
var attachment = new GlideSysAttachment();
attachment.deleteAttachment(attachmentSysID);
}
}
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2023 11:31 AM
Thank you! That worked perfectly. After hours of struggling, it now works. Thank you so much!