Skip to content

Commit 2f4ee53

Browse files
Cross table dependency analyzer (#2269)
1 parent f9dbfbe commit 2f4ee53

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
(function executeRule(current, previous /*null when async*/) {
2+
3+
var analyzer = new CrossTableDependencyAnalyzer();
4+
var deps = analyzer.getDependencies(current);
5+
6+
if (deps.length > 0) {
7+
var messages = deps.map(function(d){ return d.table + ': ' + d.number + ' (' + d.state + ')'; });
8+
current.comments = 'Potential impact on related records:\n' + messages.join('\n');
9+
}
10+
11+
})(current, previous);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
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.
2+
3+
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.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
var CrossTableDependencyAnalyzer = Class.create();
2+
CrossTableDependencyAnalyzer.prototype = {
3+
initialize: function() {},
4+
5+
// Get related records for a CI or task
6+
getDependencies: function(record) {
7+
var dependencies = [];
8+
9+
if (!record) return dependencies;
10+
11+
var ciId = record.cmdb_ci; // for incidents or changes
12+
if (ciId) {
13+
// Find active incidents for this CI
14+
var inc = new GlideRecord('incident');
15+
inc.addQuery('cmdb_ci', ciId);
16+
inc.addActiveQuery();
17+
inc.query();
18+
while (inc.next()) {
19+
dependencies.push({
20+
table: 'incident',
21+
number: inc.number.toString(),
22+
state: inc.state.toString()
23+
});
24+
}
25+
26+
// Find active changes for this CI
27+
var chg = new GlideRecord('change_request');
28+
chg.addQuery('cmdb_ci', ciId);
29+
chg.addActiveQuery();
30+
chg.query();
31+
while (chg.next()) {
32+
dependencies.push({
33+
table: 'change_request',
34+
number: chg.number.toString(),
35+
state: chg.state.toString()
36+
});
37+
}
38+
39+
// Find problems linked to this CI
40+
var prb = new GlideRecord('problem');
41+
prb.addQuery('cmdb_ci', ciId);
42+
prb.addActiveQuery();
43+
prb.query();
44+
while (prb.next()) {
45+
dependencies.push({
46+
table: 'problem',
47+
number: prb.number.toString(),
48+
state: prb.state.toString()
49+
});
50+
}
51+
}
52+
53+
return dependencies;
54+
},
55+
56+
type: 'CrossTableDependencyAnalyzer'
57+
};

0 commit comments

Comments
 (0)