SlightlyLoony
Tera Contributor

find_real_file.pngThe other day I was on the phone with a customer who wanted to write a business rule that understood CI relationships. In particular, he was trying to make a business rule that could tell if a CI had a "used by" relationship with a particular business service. He thought it would be easy, but he couldn't figure out how in the world the CI knew about the relationship with the business service. He could see it on the screen, but couldn't find a reference to the business service anywhere, in any field in the CI. Here's how we do it:

The "trick" is an old and venerable one that goes by many names. We call it a many-to-many table, but the notion is also known as a join table, a connector table, and it goes by various other names as well. For CI relationships, the table is named cmdb_rel_ci, and it contains three very useful fields:

  • parent: a CI reference to the parent CI (the one on the left side of the relationship)
  • child: a CI reference to the child CI (the one on the right side of the relationship)
  • type: a reference to an entry in the cmdb_rel_type table, which you can see at Configuration → CI Relation Types


The cmdb_rel_type table has two fields of primary interest:
  • parent_descriptor: The English description of the relationship from the parent CI's perspective, such as "depends on".
  • child_descriptor: The English description of the relationhsip from the child CI's perspective, such as "used by".


For my caller's case, he just needed to look for records in cmdb_rel_ci where the parent field pointed to the right business service, the child field pointed to the CI the business rule was on, and the type field pointed to the cmdb_rel_type entry for a depends on::used by relationship. That turned about to be about five lines of Javascript, once he understood how to do it...

2 Comments