diff --git a/Server-Side Components/Business Rules/Cross-Table Dependency Analyzer/businessrule.js b/Server-Side Components/Business Rules/Cross-Table Dependency Analyzer/businessrule.js new file mode 100644 index 0000000000..dfe171fa30 --- /dev/null +++ b/Server-Side Components/Business Rules/Cross-Table Dependency Analyzer/businessrule.js @@ -0,0 +1,11 @@ +(function executeRule(current, previous /*null when async*/) { + + var analyzer = new CrossTableDependencyAnalyzer(); + var deps = analyzer.getDependencies(current); + + if (deps.length > 0) { + var messages = deps.map(function(d){ return d.table + ': ' + d.number + ' (' + d.state + ')'; }); + current.comments = 'Potential impact on related records:\n' + messages.join('\n'); + } + +})(current, previous); diff --git a/Server-Side Components/Business Rules/Cross-Table Dependency Analyzer/readme.md b/Server-Side Components/Business Rules/Cross-Table Dependency Analyzer/readme.md new file mode 100644 index 0000000000..2db0f55614 --- /dev/null +++ b/Server-Side Components/Business Rules/Cross-Table Dependency Analyzer/readme.md @@ -0,0 +1,3 @@ +The Cross-Table Dependency Analyzer is a custom ServiceNow solution designed to dynamically detect and analyze dependencies across multiple tables such as Incidents, Problems, Changes, and Configuration Items (CIs). This tool ensures that updates to one record do not inadvertently impact related records across the system, providing better visibility, risk mitigation, and proactive management. + +Unlike out-of-the-box (OOB) impact analysis, this solution is fully customizable, real-time, and developer-driven, making it suitable for organizations with complex IT processes or interdependent services. diff --git a/Server-Side Components/Business Rules/Cross-Table Dependency Analyzer/scriptInclude.js b/Server-Side Components/Business Rules/Cross-Table Dependency Analyzer/scriptInclude.js new file mode 100644 index 0000000000..825ded824e --- /dev/null +++ b/Server-Side Components/Business Rules/Cross-Table Dependency Analyzer/scriptInclude.js @@ -0,0 +1,57 @@ +var CrossTableDependencyAnalyzer = Class.create(); +CrossTableDependencyAnalyzer.prototype = { + initialize: function() {}, + + // Get related records for a CI or task + getDependencies: function(record) { + var dependencies = []; + + if (!record) return dependencies; + + var ciId = record.cmdb_ci; // for incidents or changes + if (ciId) { + // Find active incidents for this CI + var inc = new GlideRecord('incident'); + inc.addQuery('cmdb_ci', ciId); + inc.addActiveQuery(); + inc.query(); + while (inc.next()) { + dependencies.push({ + table: 'incident', + number: inc.number.toString(), + state: inc.state.toString() + }); + } + + // Find active changes for this CI + var chg = new GlideRecord('change_request'); + chg.addQuery('cmdb_ci', ciId); + chg.addActiveQuery(); + chg.query(); + while (chg.next()) { + dependencies.push({ + table: 'change_request', + number: chg.number.toString(), + state: chg.state.toString() + }); + } + + // Find problems linked to this CI + var prb = new GlideRecord('problem'); + prb.addQuery('cmdb_ci', ciId); + prb.addActiveQuery(); + prb.query(); + while (prb.next()) { + dependencies.push({ + table: 'problem', + number: prb.number.toString(), + state: prb.state.toString() + }); + } + } + + return dependencies; + }, + + type: 'CrossTableDependencyAnalyzer' +};