Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# ServiceNow Automatic Relationship Builder
**Auto-create CMDB relationships dynamically on CI insert or update**

---

## Overview

The **Automatic Relationship Builder** ensures that your CMDB stays complete and accurate by automatically creating parent–child relationships between Configuration Items (CIs) whenever they are inserted or updated.

Instead of manually linking servers, applications, and databases, this Business Rule dynamically establishes **"Runs on"**, **"Depends on"**, or **"Connected to"** relationships based on CI attributes.

---

## Key Highlights

Builds CMDB relationships automatically
Eliminates manual linking of dependent CIs

---

## Use Case

When a new **Application CI** is created or discovered and its **host CI (server)** is known,
the script automatically builds a relationship of type **“Runs on::Runs”** between the two.

This keeps your CMDB up-to-date without human intervention.

---

## Table and Trigger

| Item | Value |
|------|-------|
| **Table** | `cmdb_ci_appl` |
| **Trigger** | After Insert / After Update |
| **Condition** | `u_host` field is populated |
| **Purpose** | Create a “Runs on” relationship between host and application |

---

## Script — Business Rule


Business Rule: Auto Relationship Builder
Table: cmdb_ci_appl
When: after insert / after update

## Example Input (New CI Record)
| Field | Value |
| ------ | ---------------------------- |
| Name | Payroll Application |
| Class | Application (`cmdb_ci_appl`) |
| u_Host | APP-SERVER-01 |
| Owner | IT Operations |

## Example Output (Created Relationship)

| Field | Value |
| ------ | ------------------- |
| Parent | APP-SERVER-01 |
| Child | Payroll Application |
| Type | Runs on :: Runs |
| Table | cmdb_rel_ci |
Relationship automatically visible in CI Relationship Viewer.


Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* Scenario :
When a new CI (like an Application Server) is discovered or updated, automatically create “Runs on”, “Depends on”,
or “Connected to” relationships based on specific patterns.*/

// Table: cmdb_ci_appl | BR: after insert/update
(function executeRule(current, previous) {
if (current.u_host) {
var rel = new GlideRecord('cmdb_rel_ci');
rel.initialize();
rel.parent = current.u_host; // parent = server
rel.child = current.sys_id; // child = application
rel.type = 'Runs on::Runs'; // relationship type
rel.insert();
}
})(current, previous);
Loading