Skip to content

Commit 796252c

Browse files
Create scriptInclude.js
1 parent 18fa403 commit 796252c

File tree

1 file changed

+57
-0
lines changed
  • Server-Side Components/Business Rules/Cross-Table Dependency Analyzer

1 file changed

+57
-0
lines changed
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)