Update CI operational status based on Incident Resolution Code?

alex2410
Tera Contributor

Hi All!

 

I am looking for help to update the related CI on an Incident Record's Operational Status based on the Resolution code of the Incident.

 

E.g. Incident is closed with Resolution Code 'Retired' and CI on Incident is 'Laptop', how can we trigger the Laptop CI record to auto update it's Operational Status to 'Retired' ?

Thank you!

Alex

 

#cmdb #itms #incident

1 ACCEPTED SOLUTION

Sandeep Rajput
Tera Patron
Tera Patron

@alex2410 You need to create a business rule which triggers when the incident state changes to resolved. You can do a glide record query in the business rule script to fetch the CI and update its operational status based on the resolution code of the incident.

 

Here is the sample script.

 

// Initialize a new GlideRecord for the cmdb_ci table
var ciGR = new GlideRecord('cmdb_ci');

// Query for the CI you want to update by its sys_id or another identifying field
ciGR.get('sys_id', current.cmdb_ci); // Replace with the actual sys_id or any other condition

// Check if the record exists
if (ciGR.isValidRecord()) {
    // Update the operational status field
   if(current.close_code=='retired'){
    ciGR.setValue('operational_status', 6); // Replace 6 with the actual value for the desired operational status
    
    // Update the CI record in the database
    var updated = ciGR.update();

    // Check if the update was successful
    if (updated) {
        gs.info('CI operational status updated successfully.');
    } else {
        gs.info('Failed to update CI operational status.');
    }
}
} else {
    gs.info('CI not found.');
}

 

Hope this helps.

View solution in original post

3 REPLIES 3

Sandeep Rajput
Tera Patron
Tera Patron

@alex2410 You need to create a business rule which triggers when the incident state changes to resolved. You can do a glide record query in the business rule script to fetch the CI and update its operational status based on the resolution code of the incident.

 

Here is the sample script.

 

// Initialize a new GlideRecord for the cmdb_ci table
var ciGR = new GlideRecord('cmdb_ci');

// Query for the CI you want to update by its sys_id or another identifying field
ciGR.get('sys_id', current.cmdb_ci); // Replace with the actual sys_id or any other condition

// Check if the record exists
if (ciGR.isValidRecord()) {
    // Update the operational status field
   if(current.close_code=='retired'){
    ciGR.setValue('operational_status', 6); // Replace 6 with the actual value for the desired operational status
    
    // Update the CI record in the database
    var updated = ciGR.update();

    // Check if the update was successful
    if (updated) {
        gs.info('CI operational status updated successfully.');
    } else {
        gs.info('Failed to update CI operational status.');
    }
}
} else {
    gs.info('CI not found.');
}

 

Hope this helps.

Hi @Sandeep Rajput ,

 

Thank you so much for getting back to me, this was a massive help and I'm almost there with it!

 

The issue I have now is, the operational status and install status are on the cmdb_ci table, these are both updating depending on incident resolution details.

 

However, I also need to update a 3rd field which is on a custom cmdb_ci table.

 

E.g . - 

ciGR.setValue('cmdb_ci_new_table.u_new_variable',''); // clear new variable value
 
Adding this to this script does not work and changing the script to only look at the cmdb_ci_new_table instead of cmdb_ci does not update the operational or install status anymore.
 
Any further help would be appreciated!
 
Thanks!
Alex

@alex2410 Could you please let me know about the structure and relation of this third custom table with your record in cmdb_ci table? 

 

Since I already addressed your original question, please mark my initial response as an accepted solution.