Add the Impacted Services from all Affected CI's to a Change
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2015 03:21 AM
I have a related list on Task called 'Impacted Services' that lists the CI's related business services. It's populated by the following Business Rule:
removeAffectedServices();
if (!current.cmdb_ci.nil())
addAffectedServices();
//Removes any affected Services currently on the list
function removeAffectedServices() {
var m2m = new GlideRecord('task_cmdb_ci_service');
m2m.addQuery('task',current.sys_id);
m2m.addQuery('manually_added','false');
m2m.query();
m2m.deleteMultiple();
}
//Adds the affected Services based on the CI
function addAffectedServices() {
var ciu = new 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();
}
}
But... it only brings back the Business Service from the main CI field - 'cmdb_ci', and nothing from the Affected CIs table 'task_ci'. I need it to bring back all services from all the affected CI's. For example, if additional CI's get added to a Change record, then the Impacted Services list should also upate to reflect the potential new affected services.
Has anyone acheived this or something similar and able to offer an insight on what I need to change.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2017 11:15 AM
Hi,
I have tried this and it worked!! But the only problem is it's creating duplicates of the impacted services. How can we prevent duplication of impacted services??
Thanks,
SD
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2017 06:53 AM
I experienced this issue as well. I tried all the fixes here and they did not help. So i changed my classes like this:
System Definition > Script Includes > CIUtils:
You'll notice i used a very workaround way to handle the array. The built in _addService methods were causing issues. Even though an array would go through the for loop setting the correct values. Upon return the values would all be set to the same value in the [0] place. Using a string as I did fixed this issue.
servicesAffectedByCI: function(id) {
var ci = new GlideRecord("cmdb_ci");
var services = new GlideRecord("svc_ci_assoc");
services.addQuery('ci_id.sys_id',id);
services.query();
var arr = '';
for (var i = 0; i< services.getRowCount();i++) {
services.next();
arr+=services.service_id+',';
}
var res = arr.split(",");
return res.splice(0,res.length-1);
},
System UI > UI Actions > Refresh Impacted Services (change_request):
function addAffectedServices() {
var ciu = new 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();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2017 11:56 AM