From 151cca4a6ccc3737f5fa4ed9aafb49e6fb963311 Mon Sep 17 00:00:00 2001 From: Jaspal <30924269+Jaspalsinghchot@users.noreply.github.com> Date: Sat, 4 Oct 2025 13:30:57 +0400 Subject: [PATCH 1/4] script.js --- .../script.js | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Server-Side Components/Background Scripts/Delete Attachments - Closed Approvals/script.js diff --git a/Server-Side Components/Background Scripts/Delete Attachments - Closed Approvals/script.js b/Server-Side Components/Background Scripts/Delete Attachments - Closed Approvals/script.js new file mode 100644 index 0000000000..0519a52d09 --- /dev/null +++ b/Server-Side Components/Background Scripts/Delete Attachments - Closed Approvals/script.js @@ -0,0 +1,41 @@ +deleteinactiveattachments(); + +//deletes from approval table +function deleteinactiveattachments() { + var appr = new GlideRecord('sysapproval_approver'); +// appr.addQuery('sys_id','2d7f326287351ad0195eb99c8bbb35b5'); //uncomment this and replace sys_id and use this to check for 1 record + appr.addEncodedQuery('state!=requested^ORstate=NULL'); + appr.query(); + while (appr.next()) { + var answer = deleteparentattachment(appr.sys_id); + deletechildattachment(appr.sys_id); + if (answer == true || answer == 'true') { + appr.comments = "Attachment's were removed from this record. If still needed it can be located at the corresponding ticket level."; + appr.autoSysFields(false); + appr.setWorkflow(false); + appr.update(); + } + } +} +//deletes from sys_attachment table +function deleteparentattachment(record) { + var attach_found = false; + var attach_primary = new GlideRecord('sys_attachment'); + attach_primary.addQuery('table_sys_id', record); + attach_primary.query(); + while (attach_primary.next()) { + attach_primary.deleteRecord(); + attach_found = 'true'; + } + return attach_found; +} + +//deletes from sys_attachment_doc table +function deletechildattachment(record) { + var attach_child = new GlideRecord('sys_attachment_doc'); + attach_child.addQuery('sys_attachment.table_sys_id', record); + attach_child.query(); + while (attach_child.next()) { + attach_child.deleteRecord(); + } +} From d092cf2f084cfe74cba7e45341e548ca056f124a Mon Sep 17 00:00:00 2001 From: Jaspal <30924269+Jaspalsinghchot@users.noreply.github.com> Date: Sat, 4 Oct 2025 13:31:25 +0400 Subject: [PATCH 2/4] readme.md --- .../Delete Attachments - Closed Approvals/readme.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Server-Side Components/Background Scripts/Delete Attachments - Closed Approvals/readme.md diff --git a/Server-Side Components/Background Scripts/Delete Attachments - Closed Approvals/readme.md b/Server-Side Components/Background Scripts/Delete Attachments - Closed Approvals/readme.md new file mode 100644 index 0000000000..d7b047a94f --- /dev/null +++ b/Server-Side Components/Background Scripts/Delete Attachments - Closed Approvals/readme.md @@ -0,0 +1,2 @@ +Many organizations still prefer copying over the attachments from RITM or any ticket type that has approval required to its corresponding approvals by using GlideSysAttachment.copy() +This ideally makes sense till the time approval is needed however, when approvals are actioned (approved/rejected) there is no need for attachments to stay on the approval record till eternity (it will be stored at its ticket level). Use this script as a scheduled script to remove attachments from closed (approved/rejected) approval records and help consume less storage. From c8807d54c3e0933aef8174d056d6f3027b64a1b8 Mon Sep 17 00:00:00 2001 From: Jaspal <30924269+Jaspalsinghchot@users.noreply.github.com> Date: Sat, 4 Oct 2025 13:48:19 +0400 Subject: [PATCH 3/4] readme.md --- .../Background Scripts/Bulk Share - Reports/readme.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 Server-Side Components/Background Scripts/Bulk Share - Reports/readme.md diff --git a/Server-Side Components/Background Scripts/Bulk Share - Reports/readme.md b/Server-Side Components/Background Scripts/Bulk Share - Reports/readme.md new file mode 100644 index 0000000000..50a2ac4b9e --- /dev/null +++ b/Server-Side Components/Background Scripts/Bulk Share - Reports/readme.md @@ -0,0 +1,3 @@ +How often we come across cases where report created by one user needs to be shared with multiple users. We can use the 'Share' option but will be time consuming. +Imagine being able to do it via script by just passing sys_id of users. +Use this script to share report in bulk by executing it as Background script From 2843bbaa4aaa24b6c0e174664dadfff8ab8178c0 Mon Sep 17 00:00:00 2001 From: Jaspal <30924269+Jaspalsinghchot@users.noreply.github.com> Date: Sat, 4 Oct 2025 13:49:46 +0400 Subject: [PATCH 4/4] script.js --- .../Bulk Share - Reports/script.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Server-Side Components/Background Scripts/Bulk Share - Reports/script.js diff --git a/Server-Side Components/Background Scripts/Bulk Share - Reports/script.js b/Server-Side Components/Background Scripts/Bulk Share - Reports/script.js new file mode 100644 index 0000000000..32b9fc09b6 --- /dev/null +++ b/Server-Side Components/Background Scripts/Bulk Share - Reports/script.js @@ -0,0 +1,14 @@ +var list = "4b6c76e3dbcfaf0000ec7abe3b961912,9e67d6d1db736300d43c54e848961934"; //pass user sys_id here who needs access to reports +var arr = list.split(","); +for(i=0;i