The CreatorCon Call for Content is officially open! Get started here.

Walk through CI relation

Yusuf5
Tera Expert

Hi Everyone,

 

I am trying to find all the ci that have the relation to as in dependency views in a script.

 

Any help is appreciated.

Regards,

Yusuf

4 REPLIES 4

Maik Skoddow
Tera Patron
Tera Patron

Hi @Yusuf5 

you just need to filter and iterate the table cmdb_rel_ci

Maik

Yusuf5
Tera Expert

Thanks Maik,

 

I am aware of that approach but I thought there might be some code that guides me to.

@Yusuf5 

 

Use below code to get relationship-

function u_getmyCIRel(ci) {

 

  var rel = '';

 

  var gr = new GlideRecord('cmdb_rel_ci');

 

  gr.addQuery('parent', ci);

 

  gr.addQuery('parent.sys_class_name', "=", 'cmdb_ci_appl');

 

  gr.addQuery('child.sys_class_name', "=", "Application Environment");

 

  gr.query();

 

gs.log(gr.getRowCount());

 

  while (gr.next()) {

 

  rel += "," + gr.child;

 

  }

 

gs.log('sys_idIN' + rel.substring(1));

 

  return 'sys_idIN' + rel.substring(1);



  }

 

Thanks,

Manjusha Bangale

This code just gives the first level how about the ci that have the connection to others?