diff --git a/Server-Side Components/Background Scripts/Cleanup Unlinked Attachments/Readme.md b/Server-Side Components/Background Scripts/Cleanup Unlinked Attachments/Readme.md new file mode 100644 index 0000000000..228d60212f --- /dev/null +++ b/Server-Side Components/Background Scripts/Cleanup Unlinked Attachments/Readme.md @@ -0,0 +1,7 @@ +Cleanup Unlinked Attachments + +Overview + +This script automatically deletes attachments that are no longer linked to any record in ServiceNow. + +Attachments that are not associated with a table or record can consume unnecessary storage and affect instance performance. diff --git a/Server-Side Components/Background Scripts/Cleanup Unlinked Attachments/script.js b/Server-Side Components/Background Scripts/Cleanup Unlinked Attachments/script.js new file mode 100644 index 0000000000..e7ee7974bb --- /dev/null +++ b/Server-Side Components/Background Scripts/Cleanup Unlinked Attachments/script.js @@ -0,0 +1,7 @@ + var att = new GlideRecord('sys_attachment'); + att.addNullQuery('table_sys_id'); + att.query(); + while (att.next()) { + gs.info('Deleting Unlinked attachment: ' + att.sys_id); + att.deleteRecord(); + }