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..74deefafc6 --- /dev/null +++ b/Server-Side Components/Background Scripts/ Bulk Change of Incident Priority Based on Category/BulkIncidentPriorityUpdater.js @@ -0,0 +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); +})(); + 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.