From 9e0afbd9d7a29a0acc268cbcc0e1f0e0fe46043f Mon Sep 17 00:00:00 2001 From: Jaspal <30924269+Jaspalsinghchot@users.noreply.github.com> Date: Thu, 24 Oct 2024 12:58:00 +0400 Subject: [PATCH 01/11] script.js --- Background Scripts/Get Duplicate/script.js | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Background Scripts/Get Duplicate/script.js diff --git a/Background Scripts/Get Duplicate/script.js b/Background Scripts/Get Duplicate/script.js new file mode 100644 index 0000000000..4ebdc39422 --- /dev/null +++ b/Background Scripts/Get Duplicate/script.js @@ -0,0 +1,8 @@ +var dpchk = new GlideAggregate('task'); +dpchk.groupBy('number'); +dpchk.addHaving('COUNT', '>', 1); +dpchk.query(); +while(dpchk.next()) +{ + gs.print(dpchk.number); +} From 5254d886b8d909175a7ec36f81ab730a2e108b26 Mon Sep 17 00:00:00 2001 From: Jaspal <30924269+Jaspalsinghchot@users.noreply.github.com> Date: Thu, 24 Oct 2024 12:59:53 +0400 Subject: [PATCH 02/11] readme.md --- Background Scripts/Get Duplicate/readme.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 Background Scripts/Get Duplicate/readme.md diff --git a/Background Scripts/Get Duplicate/readme.md b/Background Scripts/Get Duplicate/readme.md new file mode 100644 index 0000000000..23de281b78 --- /dev/null +++ b/Background Scripts/Get Duplicate/readme.md @@ -0,0 +1,3 @@ +Using GlideAggregate function to find out tickets (tasks) with same number. OOB there happens to be a Unique checkbox at dictionary level +and if in case not set to True it might create duplicate numbered tickets. +Script will help find, ticekts if any. From 82276f3778a34fa67c4fecca4596a0416e946cdb Mon Sep 17 00:00:00 2001 From: Jaspal <30924269+Jaspalsinghchot@users.noreply.github.com> Date: Sat, 4 Oct 2025 12:27:10 +0400 Subject: [PATCH 03/11] Create readme.md --- Background Scripts/Revert Workflow Version/readme.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Background Scripts/Revert Workflow Version/readme.md diff --git a/Background Scripts/Revert Workflow Version/readme.md b/Background Scripts/Revert Workflow Version/readme.md new file mode 100644 index 0000000000..a535acc1b0 --- /dev/null +++ b/Background Scripts/Revert Workflow Version/readme.md @@ -0,0 +1,4 @@ +How often you come across cases where any version update to workflow breaks some other element of the existing workflow in PRD. Consider a case where more than one developer works on workflow and the updates are not in sync. When pushed to PRD breaks the workflow and as the issue is in PRD all you need to do is a break-fix at the soonest. +The idea is to return to a stable, known version of the workflow to ensure continuity and productivity, while investigating or fixing the problems in the newer version and thus reverting to previous working version of workflow is the only resort. + +Use this as a background script/fix script and execute by merely changing the sys_id of workflows from 'wf_workflow_version' table. From ed4094405fa1ce61e8e88b7d7116a307f395560a Mon Sep 17 00:00:00 2001 From: Jaspal <30924269+Jaspalsinghchot@users.noreply.github.com> Date: Sat, 4 Oct 2025 12:28:52 +0400 Subject: [PATCH 04/11] Create script.js --- .../Revert Workflow Version/script.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Background Scripts/Revert Workflow Version/script.js diff --git a/Background Scripts/Revert Workflow Version/script.js b/Background Scripts/Revert Workflow Version/script.js new file mode 100644 index 0000000000..7879dcfd55 --- /dev/null +++ b/Background Scripts/Revert Workflow Version/script.js @@ -0,0 +1,15 @@ +var updatevftoprevious = new GlideRecord('wf_workflow_version'); + +if (updatevftoprevious.get('4f215adf1b533d54bc97dce0b24bcb31')) //pass sys_id of current workflow version here +{ + updatevftoprevious.published = false; //sets the published status to false + updatevftoprevious.update(); +} + + +var updatevftopreviousvf2 = new GlideRecord('wf_workflow_version'); +if (updatevftopreviousvf2.get('2cb9a6418713b5140b0f0d490cbb3512')) //pass sys_id of workflow version that needs to be reverted to +{ + updatevftopreviousvf2.published = true;//sets the published status to false + updatevftopreviousvf2.update(); +} From 9c963912d5483ab0ce6afd1d1871ea90a9282d67 Mon Sep 17 00:00:00 2001 From: Jaspal <30924269+Jaspalsinghchot@users.noreply.github.com> Date: Sat, 4 Oct 2025 12:40:27 +0400 Subject: [PATCH 05/11] Create readme.md --- Attachments/Delete Attachments - Approvals/readme.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 Attachments/Delete Attachments - Approvals/readme.md diff --git a/Attachments/Delete Attachments - Approvals/readme.md b/Attachments/Delete Attachments - Approvals/readme.md new file mode 100644 index 0000000000..070c3cb6b9 --- /dev/null +++ b/Attachments/Delete Attachments - Approvals/readme.md @@ -0,0 +1,3 @@ +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() +Which 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 00b905732207ab7d8a1bb8e4e1ac8f6203e761bb Mon Sep 17 00:00:00 2001 From: Jaspal <30924269+Jaspalsinghchot@users.noreply.github.com> Date: Sat, 4 Oct 2025 12:42:27 +0400 Subject: [PATCH 06/11] Create script.js --- .../Delete Attachments - Approvals/script.js | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Attachments/Delete Attachments - Approvals/script.js diff --git a/Attachments/Delete Attachments - Approvals/script.js b/Attachments/Delete Attachments - Approvals/script.js new file mode 100644 index 0000000000..0519a52d09 --- /dev/null +++ b/Attachments/Delete Attachments - 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 432eb7bf40d7a533ebf5b607d41098bd4f11fafe Mon Sep 17 00:00:00 2001 From: Jaspal <30924269+Jaspalsinghchot@users.noreply.github.com> Date: Sat, 4 Oct 2025 12:52:04 +0400 Subject: [PATCH 07/11] readme.md --- .../Revert to previous working version of workflow/readme.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Background Scripts/Revert to previous working version of workflow/readme.md diff --git a/Background Scripts/Revert to previous working version of workflow/readme.md b/Background Scripts/Revert to previous working version of workflow/readme.md new file mode 100644 index 0000000000..a535acc1b0 --- /dev/null +++ b/Background Scripts/Revert to previous working version of workflow/readme.md @@ -0,0 +1,4 @@ +How often you come across cases where any version update to workflow breaks some other element of the existing workflow in PRD. Consider a case where more than one developer works on workflow and the updates are not in sync. When pushed to PRD breaks the workflow and as the issue is in PRD all you need to do is a break-fix at the soonest. +The idea is to return to a stable, known version of the workflow to ensure continuity and productivity, while investigating or fixing the problems in the newer version and thus reverting to previous working version of workflow is the only resort. + +Use this as a background script/fix script and execute by merely changing the sys_id of workflows from 'wf_workflow_version' table. From 0c5eedf64e26056f0b9519506e50a0ed32f5aa76 Mon Sep 17 00:00:00 2001 From: Jaspal <30924269+Jaspalsinghchot@users.noreply.github.com> Date: Sat, 4 Oct 2025 12:52:28 +0400 Subject: [PATCH 08/11] script.js --- .../script.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Background Scripts/Revert to previous working version of workflow/script.js diff --git a/Background Scripts/Revert to previous working version of workflow/script.js b/Background Scripts/Revert to previous working version of workflow/script.js new file mode 100644 index 0000000000..7879dcfd55 --- /dev/null +++ b/Background Scripts/Revert to previous working version of workflow/script.js @@ -0,0 +1,15 @@ +var updatevftoprevious = new GlideRecord('wf_workflow_version'); + +if (updatevftoprevious.get('4f215adf1b533d54bc97dce0b24bcb31')) //pass sys_id of current workflow version here +{ + updatevftoprevious.published = false; //sets the published status to false + updatevftoprevious.update(); +} + + +var updatevftopreviousvf2 = new GlideRecord('wf_workflow_version'); +if (updatevftopreviousvf2.get('2cb9a6418713b5140b0f0d490cbb3512')) //pass sys_id of workflow version that needs to be reverted to +{ + updatevftopreviousvf2.published = true;//sets the published status to false + updatevftopreviousvf2.update(); +} From d3bfcf74c29062bda480c2c990e856614b72551f Mon Sep 17 00:00:00 2001 From: Jaspal <30924269+Jaspalsinghchot@users.noreply.github.com> Date: Sat, 4 Oct 2025 12:59:12 +0400 Subject: [PATCH 09/11] Delete Background Scripts/Revert Workflow Version directory --- .../Revert Workflow Version/readme.md | 4 ---- .../Revert Workflow Version/script.js | 15 --------------- 2 files changed, 19 deletions(-) delete mode 100644 Background Scripts/Revert Workflow Version/readme.md delete mode 100644 Background Scripts/Revert Workflow Version/script.js diff --git a/Background Scripts/Revert Workflow Version/readme.md b/Background Scripts/Revert Workflow Version/readme.md deleted file mode 100644 index a535acc1b0..0000000000 --- a/Background Scripts/Revert Workflow Version/readme.md +++ /dev/null @@ -1,4 +0,0 @@ -How often you come across cases where any version update to workflow breaks some other element of the existing workflow in PRD. Consider a case where more than one developer works on workflow and the updates are not in sync. When pushed to PRD breaks the workflow and as the issue is in PRD all you need to do is a break-fix at the soonest. -The idea is to return to a stable, known version of the workflow to ensure continuity and productivity, while investigating or fixing the problems in the newer version and thus reverting to previous working version of workflow is the only resort. - -Use this as a background script/fix script and execute by merely changing the sys_id of workflows from 'wf_workflow_version' table. diff --git a/Background Scripts/Revert Workflow Version/script.js b/Background Scripts/Revert Workflow Version/script.js deleted file mode 100644 index 7879dcfd55..0000000000 --- a/Background Scripts/Revert Workflow Version/script.js +++ /dev/null @@ -1,15 +0,0 @@ -var updatevftoprevious = new GlideRecord('wf_workflow_version'); - -if (updatevftoprevious.get('4f215adf1b533d54bc97dce0b24bcb31')) //pass sys_id of current workflow version here -{ - updatevftoprevious.published = false; //sets the published status to false - updatevftoprevious.update(); -} - - -var updatevftopreviousvf2 = new GlideRecord('wf_workflow_version'); -if (updatevftopreviousvf2.get('2cb9a6418713b5140b0f0d490cbb3512')) //pass sys_id of workflow version that needs to be reverted to -{ - updatevftopreviousvf2.published = true;//sets the published status to false - updatevftopreviousvf2.update(); -} From 3db995400e1237a1ceaf300a66ad6bf44c534676 Mon Sep 17 00:00:00 2001 From: Jaspal <30924269+Jaspalsinghchot@users.noreply.github.com> Date: Sat, 4 Oct 2025 13:07:34 +0400 Subject: [PATCH 10/11] Delete Background Scripts/Get Duplicate directory --- Background Scripts/Get Duplicate/readme.md | 3 --- Background Scripts/Get Duplicate/script.js | 8 -------- 2 files changed, 11 deletions(-) delete mode 100644 Background Scripts/Get Duplicate/readme.md delete mode 100644 Background Scripts/Get Duplicate/script.js diff --git a/Background Scripts/Get Duplicate/readme.md b/Background Scripts/Get Duplicate/readme.md deleted file mode 100644 index 23de281b78..0000000000 --- a/Background Scripts/Get Duplicate/readme.md +++ /dev/null @@ -1,3 +0,0 @@ -Using GlideAggregate function to find out tickets (tasks) with same number. OOB there happens to be a Unique checkbox at dictionary level -and if in case not set to True it might create duplicate numbered tickets. -Script will help find, ticekts if any. diff --git a/Background Scripts/Get Duplicate/script.js b/Background Scripts/Get Duplicate/script.js deleted file mode 100644 index 4ebdc39422..0000000000 --- a/Background Scripts/Get Duplicate/script.js +++ /dev/null @@ -1,8 +0,0 @@ -var dpchk = new GlideAggregate('task'); -dpchk.groupBy('number'); -dpchk.addHaving('COUNT', '>', 1); -dpchk.query(); -while(dpchk.next()) -{ - gs.print(dpchk.number); -} From 7ca87b65f482cd3453496f735bd6d0d6c54444d4 Mon Sep 17 00:00:00 2001 From: Jaspal <30924269+Jaspalsinghchot@users.noreply.github.com> Date: Sat, 4 Oct 2025 13:09:30 +0400 Subject: [PATCH 11/11] Delete Attachments/Delete Attachments - Approvals directory --- .../Delete Attachments - Approvals/readme.md | 3 -- .../Delete Attachments - Approvals/script.js | 41 ------------------- 2 files changed, 44 deletions(-) delete mode 100644 Attachments/Delete Attachments - Approvals/readme.md delete mode 100644 Attachments/Delete Attachments - Approvals/script.js diff --git a/Attachments/Delete Attachments - Approvals/readme.md b/Attachments/Delete Attachments - Approvals/readme.md deleted file mode 100644 index 070c3cb6b9..0000000000 --- a/Attachments/Delete Attachments - Approvals/readme.md +++ /dev/null @@ -1,3 +0,0 @@ -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() -Which 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. diff --git a/Attachments/Delete Attachments - Approvals/script.js b/Attachments/Delete Attachments - Approvals/script.js deleted file mode 100644 index 0519a52d09..0000000000 --- a/Attachments/Delete Attachments - Approvals/script.js +++ /dev/null @@ -1,41 +0,0 @@ -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(); - } -}