Auto create CI relationship

John var
Giga Contributor

HI All,

I have the requirement as follows.

1. A custom filed called "Data Center" is created on cmdb_ci_server table and the field is reference to cmdb_ci_server.

From the list view user selects the data center field. So that it should create a relation in cmdb_rel_ci table with parent as Data center and child as current record name. Also the relation type should be like Connected by::Connects.

To achieve this i have created a business rule as below.

Before insert/update - Data center changes,

Advanced:

(function executeRule(current, previous /*null when async*/) {
	
var rel = new GlideRecord('cmdb_rel_ci');
	rel.initialize();
	rel.parent = current.u_data_center;
	rel.child = current.name;
	rel.update();
	
})(current, previous);

Can someone help me to achieve this..

5 REPLIES 5

VaranAwesomenow
Mega Sage

I would be cautious in creating data center as parent and server (or any hardware) as child, while suggested relationship OOB dictates that data center contains a CI (hardware), when looking at BSM map it appears reverse, where you will end up seeing data center above CI (hardware), hence its advisable to make data center as child and hardware as parent.