Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Business Rule: After Insert or After Update on change_request
// Purpose: Create Change Tasks for each affected CI and notify its owner
(function executeRule(current, previous /*null when insert*/) {

// Query the task_ci table to get all CIs linked to this Change Request
var ciRel = new GlideRecord('task_ci');
ciRel.addQuery('task', current.sys_id);
ciRel.query();

while (ciRel.next()) {
var ci = ciRel.ci_item.getRefRecord(); // Fetch the actual CI record

if (ci.owner) { // Proceed only if CI has an owner

// Check if a Change Task for this CI and owner already exists
var existingTask = new GlideRecord('change_task');
existingTask.addQuery('change_request', current.sys_id);
existingTask.addQuery('cmdb_ci', ci.sys_id);
existingTask.addQuery('assigned_to', ci.owner);
existingTask.query();

if (!existingTask.next()) {
// Create new Change Task for CI Owner
var ct = new GlideRecord('change_task');
ct.initialize();
ct.change_request = current.sys_id;
ct.cmdb_ci = ci.sys_id;
ct.assigned_to = ci.owner;
ct.short_description = 'Review Change for your CI: ' + ci.name;
ct.insert();

// Trigger a notification event
gs.eventQueue('change.ci.owner.notification', ct, ci.owner, current.sys_id);
}
}
}

})(current, previous);
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Create Change Tasks for each affected CI and notify its owner

1. Create a Business Rule - After Insert/Update Change Request Table
2. Query the task_ci table to get all CIs linked to this Change Request
4. Fetch all the actual CI records present in the table
5. Proceed if CI has a owner, check if a Change Task for this CI and owner already exists
6. If not existing create a change task for CI owner
7. Triggers an event to notify the CI owner (email/push).
Loading