Skip to content

Commit 07596f3

Browse files
ServiceNow Automatic Relationship Builder (#2155)
* Create Catalog.js Catalog Builder API - A Scripted REST API to auto-create ServiceNow Catalog Items programmatically. * Create README.md This readme file has info about how to Automate Catalog Item Creation with a Single REST Call. * Update README.md Automate Catalog Item Creation with a Single REST Call * Delete Integration/Scripted REST Api/Create Catalog Item Dynamically/README.md * Delete Integration/Scripted REST Api/Create Catalog Item Dynamically/Catalog.js * Create relationship.js Automatic Relationship Builder on CI Update * Create README.md The ServiceNow Automatic Relationship Builder automatically creates CMDB relationships (like Runs on or Depends on) whenever a new Configuration Item (CI) is added or updated
1 parent b481665 commit 07596f3

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# ServiceNow Automatic Relationship Builder
2+
**Auto-create CMDB relationships dynamically on CI insert or update**
3+
4+
---
5+
6+
## Overview
7+
8+
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.
9+
10+
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.
11+
12+
---
13+
14+
## Key Highlights
15+
16+
Builds CMDB relationships automatically
17+
Eliminates manual linking of dependent CIs
18+
19+
---
20+
21+
## Use Case
22+
23+
When a new **Application CI** is created or discovered and its **host CI (server)** is known,
24+
the script automatically builds a relationship of type **“Runs on::Runs”** between the two.
25+
26+
This keeps your CMDB up-to-date without human intervention.
27+
28+
---
29+
30+
## Table and Trigger
31+
32+
| Item | Value |
33+
|------|-------|
34+
| **Table** | `cmdb_ci_appl` |
35+
| **Trigger** | After Insert / After Update |
36+
| **Condition** | `u_host` field is populated |
37+
| **Purpose** | Create a “Runs on” relationship between host and application |
38+
39+
---
40+
41+
## Script — Business Rule
42+
43+
44+
Business Rule: Auto Relationship Builder
45+
Table: cmdb_ci_appl
46+
When: after insert / after update
47+
48+
## Example Input (New CI Record)
49+
| Field | Value |
50+
| ------ | ---------------------------- |
51+
| Name | Payroll Application |
52+
| Class | Application (`cmdb_ci_appl`) |
53+
| u_Host | APP-SERVER-01 |
54+
| Owner | IT Operations |
55+
56+
## Example Output (Created Relationship)
57+
58+
| Field | Value |
59+
| ------ | ------------------- |
60+
| Parent | APP-SERVER-01 |
61+
| Child | Payroll Application |
62+
| Type | Runs on :: Runs |
63+
| Table | cmdb_rel_ci |
64+
Relationship automatically visible in CI Relationship Viewer.
65+
66+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* Scenario :
2+
When a new CI (like an Application Server) is discovered or updated, automatically create “Runs on”, “Depends on”,
3+
or “Connected to” relationships based on specific patterns.*/
4+
5+
// Table: cmdb_ci_appl | BR: after insert/update
6+
(function executeRule(current, previous) {
7+
if (current.u_host) {
8+
var rel = new GlideRecord('cmdb_rel_ci');
9+
rel.initialize();
10+
rel.parent = current.u_host; // parent = server
11+
rel.child = current.sys_id; // child = application
12+
rel.type = 'Runs on::Runs'; // relationship type
13+
rel.insert();
14+
}
15+
})(current, previous);

0 commit comments

Comments
 (0)