- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2024 11:18 AM
I'm new at this and not sure if I'm in the right forum but here's the issue I'm having...
Currently, in the CI list of our IP address, Approval Group, Change Group, Managed By Group and Support is showing up as empty.
I have a script in my business rules, but it does not seem to work. Am I missing anything? Anyone familiar with hot to fix this?
Here's my script:
(function executeRule(current, previous /*null when async*/) {
// Function to update fields from related CI
function updateFieldsFromRelatedCI(relatedCI) {
var updateNeeded = false;
// Update the Approval Group field if it has changed
if (relatedCI.change_control.changes() || current.change_control != relatedCI.change_control) {
current.change_control = relatedCI.change_control;
updateNeeded = true;
}
// Update the Change Group field if it has changed
if (relatedCI.assignment_group.changes() || current.assignment_group != relatedCI.assignment_group) {
current.assignment_group = relatedCI.assignment_group;
updateNeeded = true;
}
// Update the Managed By Group field if it has changed
if (relatedCI.managed_by_group.changes() || current.managed_by_group != relatedCI.managed_by_group) {
current.managed_by_group = relatedCI.managed_by_group;
updateNeeded = true;
}
// Update the Support Group field if it has changed
if (relatedCI.support_group.changes() || current.support_group != relatedCI.support_group) {
current.support_group = relatedCI.support_group;
updateNeeded = true;
}
// Update the IP Address record if any fields have changed
if (updateNeeded) {
current.update();
}
}
// Query to find all related CIs
var relatedCIs = new GlideRecord('cmdb_rel_ci');
relatedCIs.addQuery('child', current.sys_id);
relatedCIs.query();
while (relatedCIs.next()) {
var relatedCI = new GlideRecord(relatedCIs.parent.sys_class_name);
if (relatedCI.get(relatedCIs.parent.sys_id)) {
updateFieldsFromRelatedCI(relatedCI);
}
}
})(current, previous);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2024 05:36 PM
@ShaunB
If you are writing before BR then you don't have to write current.update()
Also make sure to check the table name because you writing the on IP address table and the records which are updating should be present in the same table.
Also, keep some logs to debug the script.
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2024 05:26 PM
Here's a screenshot of the Business Rules
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2024 05:36 PM
@ShaunB
If you are writing before BR then you don't have to write current.update()
Also make sure to check the table name because you writing the on IP address table and the records which are updating should be present in the same table.
Also, keep some logs to debug the script.
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2024 06:53 AM
Here's the actual script:
(function executeRule(current, previous /*null when async*/) {
// Function to update fields from related CI
function updateFieldsFromRelatedCI(cmdb_ci_ip_address) {
var updateNeeded = false;
// Update the Approval Group field if it has changed
if (cmdb_ci.change_control.changes() || current.change_control != cmdb_ci.change_control) {
current.change_control = cmdb_ci.change_control;
updateNeeded = true;
}
// Update the Change Group field if it has changed
if (cmdb.assignment_group.changes() || current.assignment_group != cmdb.assignment_group) {
current.assignment_group = cmdb.assignment_group;
updateNeeded = true;
}
// Update the Managed By Group field if it has changed
if (cmdb_ci.managed_by_group.changes() || current.managed_by_group != cmdb_ci.managed_by_group) {
current.managed_by_group = cmdb_ci.managed_by_group;
updateNeeded = true;
}
// Update the Support Group field if it has changed
if (cmdb.support_group.changes() || current.support_group != cmdb.support_group) {
current.support_group = cmdb.support_group;
updateNeeded = true;
}
// Update the IP Address record if any fields have changed
if (updateNeeded) {
current.update();
}
}
// Query to find all related CIs
var cmdb_ci = new GlideRecord('cmdb_ci_ip_address');
cmdb_ci.addQuery('child', current.ip_address);
cmdb_ci.query();
while (cmdb_ci_ip_address.next()) {
var cmdb_ci_ip_address = new GlideRecord(cmdb_ci.parent.sys_class_name);
if (cmdb_ci.get(cmdb_ci.parent.sys_id)) {
updateFieldsFromRelatedCI(cmdb_ci_ip_address);
}
}
})(current, previous);
Pretty sure my error is coming from somewhere around this area: