How can we automatically update related Items , if we update parent item in CMDB

Aswathy3
Tera Expert

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 

6 REPLIES 6

Naveen N
Tera Expert

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 

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

 

 

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

 

Hi Naveen,

 

Now the error message has gone but the related records are not updating with new Service Owner value.

 

Thanks

Aswathy