How to find upstream and downstream relation of CI using script

misry
Kilo Contributor

Hi All

How to find upstream and downstream relation of CI using script if there is "n" of relation levels.

-BSM limited to 5

-Expand limited to 100 under tree view in BSM tab,

4 REPLIES 4

palanikumar
Mega Sage

Hi,

cmdb_rel_ci table holds the relationship between ci. You need to query this table and then iterate to the parent and child records to go to the next level.

 

Thank you,

Palani

Thank you,
Palani

Direct relation only we can check from cmdb_rel_ci table.If we go for chain of relation like 150 levels for example.

You have to do a nested query.

Querying the table based on the current CI will give you immediate related CI. Then you need to query the related CI and then next related CI and so on.

Thank you,

Palani

Thank you,
Palani

BALAJI40
Mega Sage

Hi,

you can use below OOB script below to get upstream/downstream relationships.

The output returns in an ArrayList.

Then use the nested loops, to get further CI relations.

 var al = SNC.CMDBUtil.getRelatedRecords("CI sys id", "", "cmdb_ci", "cmdb_ci", "parent/child"); // returns ArrayList