Auto refresh Impacted Services
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2019 09:10 PM
I want all the impacted Services of a change record updated automatically every time there is a change in 'Affected CIs' or 'Business Service' so that I can identified the impacted Areas and Notify correct product owners about the exposure to their Services.
If the risk of changes then the record has to set back to "New" for processing again.
- Labels:
-
Change Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2019 02:12 AM
You can use a after business rule on the table with condition when current ci changes. Example below.
function onAfter(current, previous) {
//This function will be automatically called when this rule is processed.
removeAffectedServices(current);
if (!current.cmdb_ci.nil())
addAffectedServices(current);
}
function removeAffectedServices(current) {
var m2m = new GlideRecord('task_cmdb_ci_service');
m2m.addQuery('task',current.sys_id);
m2m.addQuery('manually_added','false');
m2m.query();
m2m.deleteMultiple();
}
function addAffectedServices(current) {
var ciu = new global.CIUtils();
var services = ciu.servicesAffectedByCI(current.cmdb_ci);
var m2m = new GlideRecord('task_cmdb_ci_service');
for (var i = 0; i < services.length; i++) {
m2m.initialize();
m2m.task = current.sys_id;
m2m.cmdb_ci_service = services[i];
m2m.manually_added = 'false';
m2m.insert();
}
}
P.S. If my suggestion helped then please mark as helpful and/or correct so other community members can benefit from this information.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2024 10:52 AM
Just an FYI - With this code, if there are multiple services being added under the same task and these are non-duplicated, I was seeing unique key violation errors. Got around the issue by introducing the following code in addAffectedServices function,