diff --git a/Server-Side Components/Background Scripts/Auto-Create Problem Record from Recurring Incident Patterns/readme.md b/Server-Side Components/Background Scripts/Auto-Create Problem Record from Recurring Incident Patterns/readme.md new file mode 100644 index 0000000000..aefac31c84 --- /dev/null +++ b/Server-Side Components/Background Scripts/Auto-Create Problem Record from Recurring Incident Patterns/readme.md @@ -0,0 +1,13 @@ +Automatically Create Problem Record from Repeated Incident Patterns + +This automation detects recurring incidents based on their short descriptions and automatically creates a Problem record when a defined threshold is reached (e.g., 5 similar incidents in 7 days). + +Scenario + +Multiple users report incidents with similar descriptions, FOR EXAMPLE Email not sending or VPN connection failed. + +When the number of similar incidents exceeds the threshold within the lookback period: + +A Problem record is automatically created. + +All matching incidents are linked to the Problem. diff --git a/Server-Side Components/Background Scripts/Auto-Create Problem Record from Recurring Incident Patterns/script.js b/Server-Side Components/Background Scripts/Auto-Create Problem Record from Recurring Incident Patterns/script.js new file mode 100644 index 0000000000..b5917e6e68 --- /dev/null +++ b/Server-Side Components/Background Scripts/Auto-Create Problem Record from Recurring Incident Patterns/script.js @@ -0,0 +1,55 @@ +(function() { + + var THRESHOLD = 4; // min number of similar incidents + var DAYS = 7; + + + var incGR = new GlideAggregate('incident'); + incGR.addEncodedQuery('active=true^opened_atRELATIVEGT@dayofweek@ago@' + DAYS); //Query recent incidents + incGR.groupBy('short_description'); + incGR.addAggregate('COUNT'); + incGR.query(); + + while (incGR.next()) { + var count = parseInt(incGR.getAggregate('COUNT'), 10); + var desc = incGR.short_description.toString(); + + //Checking for high repetition + if (count >= THRESHOLD) { + + //Avoid duplicate problem + var existingProb = new GlideRecord('problem'); + existingProb.addQuery('short_description', 'CONTAINS', desc); + existingProb.addQuery('active', true); + existingProb.query(); + + if (!existingProb.hasNext()) { + + //if not exist creating Problem Record + var prob = new GlideRecord('problem'); + prob.initialize(); + prob.short_description = "Recurring Incident Pattern: " + desc; + prob.description = "Auto-generated problem for " + count + + " similar incidents in the last " + DAYS + " days.\n\nExample Description:\n" + desc; + prob.u_detected_by = 'System'; + prob.state = 1; + var probSysId = prob.insert(); + + gs.info(" Created new Problem [" + prob.number + "] for repeated incidents (" + count + "): " + desc); + + //link incident with problem + var incLinkGR = new GlideRecord('incident'); + incLinkGR.addQuery('short_description', desc); + incLinkGR.addQuery('active', true); + incLinkGR.query(); + while (incLinkGR.next()) { + incLinkGR.problem_id = probSysId; + incLinkGR.update(); + } + } + } + } + + + +})();