From b1a2c8cb77ba535a423f7522df48f45a92d7b82d Mon Sep 17 00:00:00 2001 From: DhruvBhatheja <70469942+DhruvBhatheja@users.noreply.github.com> Date: Tue, 7 Oct 2025 12:51:45 +0530 Subject: [PATCH 1/2] script.js --- .../Cleanup Unlinked Attachments/script.js | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Server-Side Components/Background Scripts/Cleanup Unlinked Attachments/script.js 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(); + } From 266a986590a3e2fd6d409acc4990ce8218469f1a Mon Sep 17 00:00:00 2001 From: DhruvBhatheja <70469942+DhruvBhatheja@users.noreply.github.com> Date: Tue, 7 Oct 2025 12:53:05 +0530 Subject: [PATCH 2/2] Readme.md --- .../Cleanup Unlinked Attachments/Readme.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Server-Side Components/Background Scripts/Cleanup Unlinked Attachments/Readme.md 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.