Skip to content

Commit eef3f11

Browse files
Script.js
1 parent 06c5594 commit eef3f11

File tree

1 file changed

+26
-0
lines changed
  • Server-Side Components/Business Rules/Update CI status on Change Request closure

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
(function executeRule(current, previous) {
2+
// Run only when Change is moving to Closed
3+
if (previous.state != current.state && current.state == 'closed') {
4+
5+
gs.info('Change ' + current.number + ' closed — updating related CI statuses.');
6+
7+
// Query all CI relationships for this Change
8+
var ciRel = new GlideRecord('task_ci');
9+
ciRel.addQuery('task', current.sys_id);
10+
ciRel.query();
11+
12+
while (ciRel.next()) {
13+
if (ciRel.ci_item) {
14+
var ci = new GlideRecord('cmdb_ci');
15+
if (ci.get(ciRel.ci_item)) {
16+
17+
// Example: Update CI status
18+
ci.install_status = 1; // 1 = In Service (Active)
19+
ci.update();
20+
21+
gs.info('CI ' + ci.name + ' status updated to In Service for Change ' + current.number);
22+
}
23+
}
24+
}
25+
}
26+
})(current, previous);

0 commit comments

Comments
 (0)