- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2018 01:07 PM
Hi Team,
I need the Impacted Service/CIs tab to autopopulate with Business Services and Business Applications based on all of the selected CI's in the Affected CI tab so that we can identify impacted business services and applications when assessing the change and performing RCA's.
Please help me.
Thanks,
Kamal
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2018 05:55 AM
Please mark as Helpful or Correct Answer if you do get this working. Appreciated!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2018 04:28 PM
Hi Paul,
In Change record Impact Services Tab, Business services details has been populated automatically based on Configuration Item.
I opened the CI checked the CI Relationship It is listing many classes and values ( ie., Depends on - Business Application, Runs on - Server application , Runs on - Linux server and Contained by - Business services classes and related values).
Now user is expecting only Business application & business services autopopulate in Impact services tab.
As suggested , I have created business rule and Service impact script include.
Finally Contained by - Business services only populating not the depends on business application values.
Please help me what should I update to retrieve the values(depends on business application class and values) in Impact services tab ?
PLease find the screenshot attached here.
I have created Business rule and script include below:
Test Affected CI
table : CIs Affected [task_ci]
After Insert
(function executeRule(current, previous /*null when async*/) {
var changeGR = current.task.getRefRecord();
var ciGR = current.ci_item.getRefRecord();
gs.log('changeGR --> '+changeGR);
new ServiceImpact().refreshWithCI(changeGR, ciGR);
})(current, previous);
Script Include : Service Impact
var ServiceImpact = Class.create();
ServiceImpact.prototype = {
initialize: function(debug) {
this.debug = (debug==true); //Use this if you want to flag debugging output
},
/*
Add Impacted Services if needed based on CI
*/
refreshWithCI: function(task, ci) {
var ciu = new CIUtils();
var services = ciu.servicesAffectedByCI(ci.sys_id);
gs.log('services --> '+services);
var servicesAdded = this.addServices(task, services);
if (servicesAdded.length > 0) {
for (var j = 0; j < servicesAdded.length; j++) {
var service = new GlideRecord("cmdb_ci_service");
service.get(services[j]);
if (this.debug) gs.addInfoMessage("" + task.number + " has a new Impacted Service: " + service.name);
}
}
},
/*
Update any missing Impacted Services, leaving existing records intact
*/
refresh: function(task) {
this.addAffectedServices(task);
task.update();
},
/*
Clear out and recalculate Impacted Services
*/
refreshFull: function(task) {
this.removeAffectedServices(task);
this.addAffectedServices(task);
task.update();
},
addAffectedServices: function(task) {
//Find all impacted business services
var ciu = new CIUtils2();
var services = ciu.cisAffectedByTask(task);
this.addServices(task, services);
},
addServices: function(task, services) {
var servicesAdded = [];
var m2m = new GlideRecord('task_cmdb_ci_service');
for (var i = 0; i < services.length; i++) {
var exists = this.isServiceImpact(task.sys_id, services[i]);
if (exists == false) {
m2m.initialize();
m2m.task = task.sys_id;
m2m.cmdb_ci_service = services[i];
m2m.manually_added = 'false';
m2m.insert();
servicesAdded.push(services[i]);
}
}
return servicesAdded;
},
isServiceImpact: function(task, service) {
var m2m = new GlideRecord('task_cmdb_ci_service');
m2m.addQuery('task', task);
m2m.addQuery('cmdb_ci_service', service);
m2m.addQuery('manually_added', 'false');
m2m.query();
return (m2m.getRowCount() > 0);
},
type: 'ServiceImpact'
};
/*--------------------- */
var ServiceImpact1 = Class.create();
ServiceImpact1.prototype = {
initialize: function(debug) {
this.debug = (debug==true); //Use this if you want to flag debugging output
},
/*
Add Business Application if needed based on CI
*/
refreshWithCI1: function(task, ci) {
var ciu = new CIUtils();
var businessapp = ciu.servicesAffectedByCI(ci.sys_id);
gs.log('businessapp --> '+businessapp);
var businessappAdded = this.addServices(task, businessapp);
if (businessappAdded.length > 0) {
for (var j = 0; j < businessappAdded.length; j++) {
var businessapp1 = new GlideRecord("u_cmdb_ci_business_app");
businessapp1.get(businessapp[j]);
if (this.debug) gs.addInfoMessage("" + task.number + " has a new Impacted Service: " + businessapp1.name);
}
}
},
/*
Update any missing Business Application, leaving existing records intact
*/
refresh1: function(task) {
this.addAffectedServices(task);
task.update();
},
/*
Clear out and recalculate Impacted Services
*/
refreshFull1: function(task) {
this.removeAffectedServices(task);
this.addAffectedServices(task);
task.update();
},
addAffectedServices: function(task) {
//Find all impacted business applications
var ciu = new CIUtils2();
var businessapp = ciu.cisAffectedByTask(task);
this.addServices(task, businessapp);
},
addServices: function(task, businessapp) {
var businessappAdded = [];
var m2m = new GlideRecord('task_cmdb_ci_service');
for (var i = 0; i < businessapp.length; i++) {
var exists = this.isServiceImpact1(task.sys_id, businessapp[i]);
if (exists == false) {
m2m.initialize();
m2m.task = task.sys_id;
m2m.u_cmdb_ci_business_app = businessapp[i];
m2m.manually_added = 'false';
m2m.insert();
businessappAdded.push(businessapp[i]);
}
}
return businessappAdded;
},
isServiceImpact1: function(task, service) {
var m2m = new GlideRecord('task_cmdb_ci_service');
m2m.addQuery('task', task);
m2m.addQuery('u_cmdb_ci_business_app', businessapp1);
m2m.addQuery('manually_added', 'false');
m2m.query();
return (m2m.getRowCount() > 0);
},
type: 'ServiceImpact1'
};

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2018 08:27 AM
Out of the box, ServiceNow will only add Services to this list, not Business Applications. At least that is the case in our instance which used out of box classes. The related list itself classifies the Service field as a Service, so you cannot add a Business Application to it (unless you reclassify it after the fact). I understand and agree that it would be helpful to put Business Applications into this list as well. However, to my knowledge this is not supported out of box. Would be interested to know as well whether others have found solutions to this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2018 12:46 PM
Hi Paul,
You are right. It is populating all the values.
Now my problem here is if we remove a CI from the Affected Tab, the related business application/services still stay there... so pretty much the Impacted Services tab does not stay up to date on what is in the Affected Tab.
So when ever I remove a CI from Affected tab, related business application/services remove from the services Impact/CI tab.
Please Help me.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2018 01:34 PM
The short answer is that it's probably best not to do this. Here's why:
If you run a business rule on each affected CI when it is added, it's easy to reduce the amount of redundant code execution, because you can just calculate only the ones for that CI, then scan through the services and add the ones that are not already added.
But to reverse this, you would need to first figure out what affected CIs you were removing and which services are impacted by those CIs, but you could not safely go ahead and remove those services, because they may still be impacted by other affected CIs that you are not removing. You would therefore have to check each and every affected CI to make sure it is save to remove the service. And you'd need to do this repeatedly for each CI. So it would be exponentially more expensive to run this code than to just do a full refresh. Furthermore, even if you are doing a full refresh, the business rule on the affected CI table would be inadequate, because it would run once for each CI.
So, the best way to account for this is some asynchronous process that would automatically do a full refresh as needed. You could either set a flag on the Task and run it as needed, or you could run the manual refresh at certain stages on the Task lifecycle, or just run it on a schedule.
To truly to an automated refresh for both addition and removal of CIs from the affected CIs table, you would need to have a pre-populated many-to-many table that was kept up to date with the impacted services for any and all CIs. There is such a table if you have Service Mapping installed. Otherwise you would need to build it and keep it up to date on your own. Otherwise, my best suggestion is just to queue a full refresh. If you're looking for a stop-gap solution, you could just prompt your user to do it manually by displaying an information message. These are all just suggestions. Currently we do asynchronous full refresh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2018 08:28 AM
Hi Paul,
I have informed to the user regarding removing the CI from the change record. Already Ui action is existing Refresh impacted services. need to click the ui action it will remove releated services. They are not agree. They want when ever save the record it will remove. I created new Br, it is not working. so I checked your script include code. It is having only add functionality. Please provide me the delete function. If remove Impact CI it need to removed corresponding services.
I will include in my script include.
var ServiceImpact = Class.create();
ServiceImpact.prototype = {
initialize: function(debug) {
this.debug = (debug==true); //Use this if you want to flag debugging output
},
/*
Add Impacted Services if needed based on CI
*/
refreshWithCI: function(task, ci) {
var ciu = new CIUtils();
var services = ciu.servicesAffectedByCI(ci.sys_id);
gs.log('services --> '+services);
var servicesAdded = this.addServices(task, services);
if (servicesAdded.length > 0) {
for (var j = 0; j < servicesAdded.length; j++) {
var service = new GlideRecord("cmdb_ci_service");
service.get(services[j]);
if (this.debug) gs.addInfoMessage("" + task.number + " has a new Impacted Service: " + service.name);
}
}
},
/*
Update any missing Impacted Services, leaving existing records intact
*/
refresh: function(task) {
this.addAffectedServices(task);
task.update();
},
/*
Clear out and recalculate Impacted Services
*/
refreshFull: function(task) {
this.removeAffectedServices(task);
this.addAffectedServices(task);
task.update();
},
addAffectedServices: function(task) {
//Find all impacted business services
var ciu = new CIUtils2();
var services = ciu.cisAffectedByTask(task);
this.addServices(task, services);
},
addServices: function(task, services) {
var servicesAdded = [];
var m2m = new GlideRecord('task_cmdb_ci_service');
for (var i = 0; i < services.length; i++) {
var exists = this.isServiceImpact(task.sys_id, services[i]);
if (exists == false) {
m2m.initialize();
m2m.task = task.sys_id;
m2m.cmdb_ci_service = services[i];
m2m.manually_added = 'false';
m2m.insert();
servicesAdded.push(services[i]);
}
}
return servicesAdded;
},
isServiceImpact: function(task, service) {
var m2m = new GlideRecord('task_cmdb_ci_service');
m2m.addQuery('task', task);
m2m.addQuery('cmdb_ci_service', service);
m2m.addQuery('manually_added', 'false');
m2m.query();
return (m2m.getRowCount() > 0);
},
type: 'ServiceImpact'
};