Auto create CI relationship
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2022 12:25 PM
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..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2022 03:54 PM
you are missing the rel_type, parent and child are sys ids of the 2 records
also, that is not how the relationship between server and DC is usually represented, you may be looking for the location on the CI
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2022 04:58 AM
MY BR is BELOW
(function executeRule(current, previous /*null when async*/) {
// var dc = current.u_data_center.getDisplayValue();
// var n = current.name.getDisplayValue();
var rel = new GlideRecord('cmdb_rel_ci');
rel.initialize();
rel.parent = current.u_data_center;
rel.child = current.name;
rel.type = '55c95bf6c0a8010e0118ec7056ebc54d';
rel.insert();
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2022 08:27 AM
if current is the server, then rel.child = current.name; should simply be
rel.child = current.sys_id;
Rels operate on sys_id not names, Data Center works because the value in the field is a sys_id referencing the DC
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2022 09:34 AM
(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.type = ' '// sys_id of Connected by::Connects record --Relation type
rel.update();
})(current, previous);
Thanks,
Mark it helpful if it works!!