How to find upstream and downstream relation of CI using script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2021 06:24 AM
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,

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2021 06:30 AM
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
Palani
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2021 06:31 AM
Direct relation only we can check from cmdb_rel_ci table.If we go for chain of relation like 150 levels for example.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2021 06:40 AM
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
Palani
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2021 07:10 AM
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