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
08-17-2016 10:35 AM
I've got the same requirement but for the UI Action "Refresh Impacted Services" which you get Out of the box.
What do I need to change to get it to work? No Impacted Services are being added with the script below.
I added a log on line 27 to check the value of aff_ci and it contained 2 sys_id.
Maybe kalai has some input?
current.update();
action.setRedirectURL(current);
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 aff_ci = [];
var affectedItem = new GlideRecord('task_ci');
affectedItem.addQuery('task', current.sys_id);
affectedItem.query();
while (affectedItem.next()) {
aff_ci.push(affectedItem.ci_item.toString());
}
var ciu = new CIUtils();
var services = ciu.servicesAffectedByCI(aff_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-18-2016 02:08 AM
The issue seems to be the services.length is returning 0, therefore nothing is inserted. Any idea what need to be updated?
Is it something in the Script Include CIUtils or something in the UI Action?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2016 02:47 AM
I think I've got it to work now, had to do some changes in the Script Include CIUtils to get it to work.
The changes are made to servicesAffectedByCI, the updated code is as follows
servicesAffectedByCI: function(id) {
var ci = new GlideRecord("cmdb_ci");
var array = id.split(',');
for (var a=0; a < array.length; a++) {
if (ci.get(array[a])) {
if (ci.sys_class_name == "cmdb_ci_service")
this._addService(array[a], this.services);
this._addParentServices(array[a], this.services, this.currentDepth);
}
}
var svcarr = new Array(); // services is an Object, convert to Array for final query
for (var i in this.services)
svcarr.push(i);
return svcarr; // list of affected services
},
The UI Action looks like this
current.update();
action.setRedirectURL(current);
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 aff_ci = [];
var affectedItem = new GlideRecord('task_ci');
affectedItem.addQuery('task', current.sys_id);
affectedItem.query();
while (affectedItem.next()) {
aff_ci.push(affectedItem.ci_item.toString());
}
var ciu = new CIUtils();
var services = ciu.servicesAffectedByCI(aff_ci.toString());
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
10-18-2016 07:23 AM
Did you have to do anything to the business rule mentioned above? I have the same requirement (refresh impacted services on Change not working)....I tried your code updates but I still get nothing returned.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2016 08:21 AM
We're not using a business rule for this, it's done by our UI Action.
Try adding some log for each variable to see what they contain and maybe you can find out where it's not working.