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

Hi Ankur,

Can you help please?

Regards,

Archie

Hi Archie,

Did you check the related list table is a m2m table? Are you populating it via script?

Regards

Ankur

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