How can we automatically update related Items , if we update parent item in CMDB
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2024 09:17 PM
Hi Team,
We need to automatically update related Items , if we update parent item in CMDB.
Eg:- Support I have updated the Service Owner of main Item of parent, then it needs to be automatically updated and reflected in its related records.
Please help me on this.
Thanks in advance
Aswathy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2024 09:32 PM
Create a business rule to update all child tables as I assume related tables is child tables
var table = new TableUtils(current.getTableName());
var childTables = table.getTableExtensions();
var fieldToUpdate = 'service_owner';//write logic get your field
// Loop through each child table
childTables.forEach(function(childTable) {
var gr = new GlideRecord(childTable);
gr.addQuery('parent', current.sys_id);
gr.query();
// Update the 'service_owner' field for each record in the child table
while (gr.next()) {
gr.setValue("fieldToUpdate",current.service_owner);//change according to requirement
gr.update();
}
});
})(current, previous);
If you find this answer correct, please mark it is as a Solution.
Reagards,
Naveen G N
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2024 11:24 PM
Hi Naveen,
Tried with BR and now getting error message while updating the Service Owner of an Application software .
We are expecting same SO needs to be updated in the related linux server of updated application software.
Error message that getting while updation - "Illegal access to method forEach(function) in class java.util.ArrayList"
Can you please check?
Thanks
Aswathy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2024 05:26 AM
Can you try below code
var table = new TableUtils(current.getTableName());
var childTables = table.getTableExtensions();
var fieldToUpdate = 'service_owner'; //write logic get your field
// Loop through each child table
for (var i = 0; i < childTables.size(); i++) {
var childTable = childTables.get(i);
var gr = new GlideRecord(childTable);
gr.addQuery('parent', current.sys_id);
gr.query();
// Update the 'service_owner' field for each record in the child table
while (gr.next()) {
gr.setValue(fieldToUpdate, current.service_owner); //change according to requirement
gr.update();
}
}
Can you please mark it correct
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2024 08:26 PM
Hi Naveen,
Now the error message has gone but the related records are not updating with new Service Owner value.
Thanks
Aswathy