Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

need to auto populate impacted services from affected cis in the related list

archie5
Tera Guru

I need to auto-populate impacted services from affected cis in the related list.

find_real_file.pngI have written a display BR below which is not populating services, Can you tell me what's missing?

function onDisplay(current, g_scratchpad) {
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 affectedItem = new GlideRecord('task_ci');
affectedItem.addQuery('task', current.sys_id);
affectedItem.query();
var aff_ci;
while (affectedItem.next()) {
aff_ci = 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();
}
}
}

 

 

6 REPLIES 6

VigneshMC
Mega Sage

I think this has to be a after insert /delete BR on affected CI's table

(function executeRule(current, previous /*null when async*/) {

if(current.operation()=='insert'){
	var impacted_ci = new GlideRecord('task_cmdb_ci_service');
	impacted_ci.initialize();
	impacted_ci.task = current.task;
	impacted_ci.cmdb_ci_service = current.ci_item;
	impacted_ci.insert();
}
	else{
		var impacted_ci_del = new GlideRecord('task_cmdb_ci_service');
	impacted_ci_del.addQuery('task',current.task);
	impacted_ci_del.addQuery('cmdb_ci_service',current.ci_item);
	impacted_ci_del.query();
	while(impacted_ci_del.next()){
	impacted_ci_del.delete();
	}
	}

})(current, previous);

 

I have to show this on change record. Have to add impacted services based on affected ci for the corresponding change record.

find_real_file.png

Hi,

you need to populate the records in that related list table based on the affected cis

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

Thank for your reply.  I have add the service 'Services Test' for this server 'SAP AppSRV01'.

find_real_file.pngfind_real_file.png

find_real_file.pngBut nothing got populated in the Impacted services. What else do I need to do?

 

Regards,

Archie