- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2024 12:14 PM
Hello, I wanted to set up an automatic calculation for how many rack units are occupying a rack. I've created a field entry for the devices with the expectation that they will have a value for how many rack units they will occupy (such as servers and any other devices that could be installed within a rack such as switches, routers, PSUs, etc). And then the plan would be for using the CI Relationship "contains::contained by" to pull the items within the rack and then sum up the rack units and display for the "Rack units in use" field on a given Rack. Currently I have the field on the Servers table (cmdb_ci_servers) and planning on adding the field to more later as we identify what items will be tracked in the Racks. I presume I will be using the Script type rather than Formula.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2024 10:26 PM
Instead of creating a new GlideRecord, you can directly access the child CI like this:
// Initialize the sum
var totalRackUnits = 0;
// Get the list of CIs contained by the rack
var grContainment = new GlideRecord('cmdb_rel_ci');
grContainment.addQuery('parent', current.sys_id); // Assuming current is the Rack CI
grContainment.addQuery('type.name', 'contains::contained by');
grContainment.query();
while (grContainment.next()) {
if (grContainment.child) { // Directly check if the child CI exists
totalRackUnits += parseInt(grContainment.child.u_rack_units || 0); // Access the rack units field from child CI
}
}
// Update the rack's "Rack units in use" field
current.u_rack_units_in_use = totalRackUnits;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2024 10:26 PM
Instead of creating a new GlideRecord, you can directly access the child CI like this:
// Initialize the sum
var totalRackUnits = 0;
// Get the list of CIs contained by the rack
var grContainment = new GlideRecord('cmdb_rel_ci');
grContainment.addQuery('parent', current.sys_id); // Assuming current is the Rack CI
grContainment.addQuery('type.name', 'contains::contained by');
grContainment.query();
while (grContainment.next()) {
if (grContainment.child) { // Directly check if the child CI exists
totalRackUnits += parseInt(grContainment.child.u_rack_units || 0); // Access the rack units field from child CI
}
}
// Update the rack's "Rack units in use" field
current.u_rack_units_in_use = totalRackUnits;