Skip to content

Commit 927a3c6

Browse files
Create Change Tasks for each affected CI and notify its owner (#2516)
* BRScript.js * README.md * BRScript.js
1 parent 96ad81c commit 927a3c6

File tree

2 files changed

+46
-0
lines changed
  • Server-Side Components/Business Rules/Auto-assign and notify owners of Affected CIs

2 files changed

+46
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Business Rule: After Insert or After Update on change_request
2+
// Purpose: Create Change Tasks for each affected CI and notify its owner
3+
(function executeRule(current, previous /*null when insert*/) {
4+
5+
// Query the task_ci table to get all CIs linked to this Change Request
6+
var ciRel = new GlideRecord('task_ci');
7+
ciRel.addQuery('task', current.sys_id);
8+
ciRel.query();
9+
10+
while (ciRel.next()) {
11+
var ci = ciRel.ci_item.getRefRecord(); // Fetch the actual CI record
12+
13+
if (ci.owner) { // Proceed only if CI has an owner
14+
15+
// Check if a Change Task for this CI and owner already exists
16+
var existingTask = new GlideRecord('change_task');
17+
existingTask.addQuery('change_request', current.sys_id);
18+
existingTask.addQuery('cmdb_ci', ci.sys_id);
19+
existingTask.addQuery('assigned_to', ci.owner);
20+
existingTask.query();
21+
22+
if (!existingTask.next()) {
23+
// Create new Change Task for CI Owner
24+
var ct = new GlideRecord('change_task');
25+
ct.initialize();
26+
ct.change_request = current.sys_id;
27+
ct.cmdb_ci = ci.sys_id;
28+
ct.assigned_to = ci.owner;
29+
ct.short_description = 'Review Change for your CI: ' + ci.name;
30+
ct.insert();
31+
32+
// Trigger a notification event
33+
gs.eventQueue('change.ci.owner.notification', ct, ci.owner, current.sys_id);
34+
}
35+
}
36+
}
37+
38+
})(current, previous);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Create Change Tasks for each affected CI and notify its owner
2+
3+
1. Create a Business Rule - After Insert/Update Change Request Table
4+
2. Query the task_ci table to get all CIs linked to this Change Request
5+
4. Fetch all the actual CI records present in the table
6+
5. Proceed if CI has a owner, check if a Change Task for this CI and owner already exists
7+
6. If not existing create a change task for CI owner
8+
7. Triggers an event to notify the CI owner (email/push).

0 commit comments

Comments
 (0)