From f75160fe56a236d25c1c3e589db6e1bcd3c3d085 Mon Sep 17 00:00:00 2001 From: Sachin Narayanasamy <132642563+SachinNarayanasamy@users.noreply.github.com> Date: Fri, 17 Oct 2025 23:26:51 +0530 Subject: [PATCH 1/3] Create readme.md --- .../readme.md | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Server-Side Components/Background Scripts/ Bulk Change of Incident Priority Based on Category/readme.md diff --git a/Server-Side Components/Background Scripts/ Bulk Change of Incident Priority Based on Category/readme.md b/Server-Side Components/Background Scripts/ Bulk Change of Incident Priority Based on Category/readme.md new file mode 100644 index 0000000000..f8290090c6 --- /dev/null +++ b/Server-Side Components/Background Scripts/ Bulk Change of Incident Priority Based on Category/readme.md @@ -0,0 +1,39 @@ +Bulk Incident Priority Updater +Overview + +This ServiceNow background script automatically updates the priority of multiple incidents based on their category. +It helps administrators and developers maintain consistent priority levels aligned with business rules — without manual updates. + +Use Case + +Here’s how it works: + +Incidents under the Network category are set to Priority 1 (Critical) + +Incidents under Application are set to Priority 2 (High) + +Incidents under Hardware are set to Priority 3 (Moderate) + +This approach saves time and ensures priority values remain standardized across the platform. + +Script Details +Field Value +Table incident +Type Background Script +Author Sachin Narayanasamy +Language JavaScript (GlideRecord) +Logic Flow + +Define a category-to-priority mapping inside the script. + +Query all active incidents in the system. + +For each incident: + +Retrieve its category. + +If the category exists in the mapping and the current priority is different, update the record. + +Log updates for each incident with its number and new priority. + +Display a summary showing how many incidents were updated and skipped. From f046c8babe986e333410bba6d1a3adefe84835c8 Mon Sep 17 00:00:00 2001 From: Sachin Narayanasamy <132642563+SachinNarayanasamy@users.noreply.github.com> Date: Fri, 17 Oct 2025 23:27:44 +0530 Subject: [PATCH 2/3] Create BulkIncidentPriorityUpdater.js --- .../BulkIncidentPriorityUpdater.js | 1 + 1 file changed, 1 insertion(+) create mode 100644 Server-Side Components/Background Scripts/ Bulk Change of Incident Priority Based on Category/BulkIncidentPriorityUpdater.js diff --git a/Server-Side Components/Background Scripts/ Bulk Change of Incident Priority Based on Category/BulkIncidentPriorityUpdater.js b/Server-Side Components/Background Scripts/ Bulk Change of Incident Priority Based on Category/BulkIncidentPriorityUpdater.js new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/Server-Side Components/Background Scripts/ Bulk Change of Incident Priority Based on Category/BulkIncidentPriorityUpdater.js @@ -0,0 +1 @@ + From db1dd2e98f1091b0dc88ad782c6106e2da566339 Mon Sep 17 00:00:00 2001 From: Sachin Narayanasamy <132642563+SachinNarayanasamy@users.noreply.github.com> Date: Fri, 17 Oct 2025 23:40:21 +0530 Subject: [PATCH 3/3] Update BulkIncidentPriorityUpdater.js Incident update by bulk on terms of category --- .../BulkIncidentPriorityUpdater.js | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/Server-Side Components/Background Scripts/ Bulk Change of Incident Priority Based on Category/BulkIncidentPriorityUpdater.js b/Server-Side Components/Background Scripts/ Bulk Change of Incident Priority Based on Category/BulkIncidentPriorityUpdater.js index 8b13789179..74deefafc6 100644 --- a/Server-Side Components/Background Scripts/ Bulk Change of Incident Priority Based on Category/BulkIncidentPriorityUpdater.js +++ b/Server-Side Components/Background Scripts/ Bulk Change of Incident Priority Based on Category/BulkIncidentPriorityUpdater.js @@ -1 +1,43 @@ +/** + * Script Name: Bulk Incident Priority Updater + * Description: + * This script automates the bulk update of incident priorities based on predefined category mappings. + * It iterates through all active incidents, checks their category, + * and updates the priority field accordingly using the mapping defined below. + + * Table: incident + * Type: Background Script + * Author: Sachin Narayanasamy + **/ + +(function() { + var priorityMapping = { + 'network': 1, // Critical + 'application': 2, // High + 'hardware': 3 // Moderate + }; + + var updatedCount = 0; + var skippedCount = 0; + + var incidentGR = new GlideRecord('incident'); + incidentGR.addQuery('active', true); + incidentGR.query(); + + while (incidentGR.next()) { + var category = incidentGR.category.toString(); + var newPriority = priorityMapping[category]; + + if (newPriority && incidentGR.priority != newPriority) { + incidentGR.priority = newPriority; + incidentGR.update(); + updatedCount++; + gs.info('Updated Incident: ' + incidentGR.number + ' → Priority set to: ' + newPriority); + } else { + skippedCount++; + } + } + + gs.info('Bulk Priority Update completed. Updated: ' + updatedCount + ', Skipped: ' + skippedCount); +})();