- 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 04:12 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2024 04:37 PM
BR = Business Rules correct? Here's a screenshot.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2024 05:25 PM
Hi Murty! Here's a screenshot
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2024 04:30 AM
@Murthy Ch Sorry for the spam! I thought my messages weren't appearing cause of an issue. Didn't know I had to wait for approval for every message I send...