Autopopulate Impacted Services/CIs Tab

kks
Tera Contributor

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

1 ACCEPTED SOLUTION

Please mark as Helpful or Correct Answer if you do get this working.  Appreciated!

View solution in original post

12 REPLIES 12

Paul Coste2
Giga Expert

Try fooling around with this. It's written assuming that you are using both the out of box CIUtils and the CIUtils2 script from SNGuru. But you could probably rewrite it if you aren't using CIUtils2. This was written on top of something that was already customized a bit, so it may not work exactly as is. It should give you a basic idea though.

This is a Script Include called ServiceImpact, that would be called from a business rule on the Affected CIs (task_ci) table. Just call the appropriate method on the object based on the event that happened. The purpose of this script is to minimize the need to recalculate all of the impacted services by just adding the services that depend on affected CIs that are added, and only if they aren't already present. This cuts down on the performance hits that you would otherwise see from automated refresh. If you need to, you can still do a full refresh as well (e.g. from the UI Action on the Task).

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); 
		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'
};

kks
Tera Contributor

Hi Paul,

 

As suggested i tried it is not working. I am submitting a change with configuration detail.

I checked the Affected CI tab it is updating the Configuration item details. But I checked the Impacted services/CI tab it is not updating the CI Relationships i.e., Business  application and  Business services.

Please Suggest me.

 

Thanks,

Kamal

Make sure you reload the form or refresh the items in the list, as it will not refresh the display automatically.  Aside from that all I can suggest is to use the JavaScript debugger to see what is going wrong.  As mentioned, your instance will probably need to tweak this a bit.  This was only meant as a starting point.  That said, we use this approach and it works great.  Good luck!

Please mark as Helpful or Correct Answer if you do get this working.  Appreciated!