populate child ci and parent ci as per selected ci

--oooo--
Tera Contributor

Hello All,

I have written the script I am able to populate parent ci and child ci .but i want all children as well as parent ci as per hierarchy.

for ex: blackberry--->child ci [email and INSIGHT-NY-03]again find out child of email and insight ny 03 till end.

can anyone please guide me?

Thank You.

 

 

----------------Before update and insert Business rule:-------------------------

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

var parci = [];
var chci = [];
var chci1 = [];
var gr = new GlideRecord('cmdb_rel_ci');
gr.addQuery('parent', current.u_configuration_items);
gs.addInfoMessage("cureent ci"+current.u_configuration_items);
gr.query();
while (gr.next()) {


// chci.push(gr.child.toString());
gs.addInfoMessage(gr.child.getDisplayValue());
// chci.push(gr.child.getDisplayValue());
chci.push(gr.child);
var c = gr.getRowCount();
}
if (c > 0) {
for (var i = 0; i <= c; i++) {
gs.addInfoMessage("sysid:"+chci[i]);

var gr12 = new GlideRecord('cmdb_rel_ci');
gr12.addQuery('parent',chci[i]);
gr12.query();
gs.addInfoMessage(gr12.next());
while (gr12.next()) {


// chci.push(gr.child.toString());
gs.addInfoMessage("child of child"+gr12.child.getDisplayValue());
chci1.push(gr12.child.getDisplayValue());

}

 

}
}


current.u_parent_ci = chci.join();

 


// gs.addInfoMessage(gr.parent.toString());//giving sys id

// gs.addInfoMessage(current.u_parent_ci.getDisplayValue());
//gs.addInfoMessage("child"+gr.parent.getDisplayValue());//giving proper name


var gra = new GlideRecord('cmdb_rel_ci');
gra.addQuery('child', current.u_configuration_items);
gra.query();
while (gra.next()) {
// gs.addInfoMessage("parent" + gra.parent.getDisplayValue());
parci.push(gra.parent.getDisplayValue());

}
current.u_new_child_ci = parci.join();

})(current, previous);

 

2 REPLIES 2

--oooo--
Tera Contributor

Manoj6
Tera Expert

This could be tricky script. You need to add "Depth" , as obtaining all parent and child relationship could potentially result in performance impact.  Additionally, ServiceNow OOB in BSM map you can select depth manually and check required relationships.