Skip to content

Commit 2b2f9d6

Browse files
Update ci status on change request closure (#2627)
* Script.js * README.md
1 parent 119664a commit 2b2f9d6

File tree

2 files changed

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

2 files changed

+35
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Update CI status on Change Request Closure
2+
3+
1. Create a Business Rule - After Update
4+
2. Select the Change Request Table.
5+
3. Add a condition as when Change state = "Closed"
6+
4. Run only when Change is moving to Closed
7+
5. Query all CI relationships for this Change Request
8+
6. Update CI status based on the condition
9+
7. The relationship table that links a change (task) to CIs (ci_item).
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)