Auto Populate Impacted Services/CI's related list tab based on Affected CIs

sureas
Mega Contributor

Friends,

In Change Form, I am trying to auto populate Impacted Service/CI's related list Tabs based on Affected CI related list. This include all the 'auto' found CIs ( CI Selected during Change Submission)as well as the manually added CI's through affected CI   tab.   I have tried to configure it trough Display BR but its not working. Could you please someone help on this?

find_real_file.png

find_real_file.png

BR Info : On Display ( When record is inserted/updated with No Condition)

============================================================

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

 

 

removeAffectedServices();   // First, search for all m2m records for the current task and delete if there are any  

addAffectedServices();         // Use the CIUtils script include to find all related services to the CI selected in the task and add m2m records  

 

 

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();      

}      

}      

 

 

function removeAffectedServices() {  

var m2m = new GlideRecord('task_cmdb_ci_service');  

m2m.addQuery('task',current.sys_id);  

m2m.query();  

m2m.deleteMultiple();  

}  

 

 

})(current, previous);  

4 REPLIES 4

ruzzty06
Tera Expert

in the line: var services = ciu.servicesAffectedByCI(current.cmdb_ci);    



what is the current.cmdb_ci?


him001
ServiceNow Employee
ServiceNow Employee

Hi Suresh,


You are only taking   the 'cmdb_ci' configuration item, while you should take all the affected CI's from the list.


Instead of having a display BR, you can have a UI action, which will do all the populating task on demand and will be performance friendly as well.



In UI action you can have code as below:



------------------------------------------------------


current.update();


action.setRedirectURL(current);


removeAffectedServices();



if (!current.cmdb_ci.nil())


addAffectedServices();



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();


}



function addAffectedServices() {


var ciu = new CIUtils();


var arrUtil = new global.ArrayUtil();


var services = [];


// Get all the Affected CIs from the list


var gr = new GlideRecord('task_ci');


gr.addQuery('task', current.getUniqueValue());


gr.query();


// Concatenate all the services into an array


while (gr.next()) {


var arr = ciu.servicesAffectedByCI(gr.getValue('ci_item'));


services = services.concat(arr);


}



if (services.length > 0)


services = arrUtil.unique(services); // avoid duplicate entries



// Inset into the table


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();


}


}



----------------------------------------




Hope this helps.



Thanks,


Himanshu


So I have done this and activated the UI Action but my impacted service is still not populating? Could it be that I don't have the relationship set up correctly? I currently have the Business service depending on a software package. There are a lot of option to choose from for relationships but nothing I have found explains the relationships I need to set up and why?

Himanshu,

You replied "...affected CI's from the list...." Do you know the definition for Affected CI's?

find_real_file.png

Is the CI Related list above the values that can be displayed in the incident's tab, Affected CI's?