Cleanup of terminated VM instances from ServiceNow CMDB
This article explains how to remove Virtual Machine instance records from the cmdb_ci_vm_instance table in ServiceNow that are marked as deleted in Flexera One IT Visibility. This ensures synchronization between Flexera One and the ServiceNow CMDB for accuracy and consistency across both systems.
Background
When a Virtual Machine is deleted in Flexera One IT Visibility, the Delta API sends the corresponding data to the Hardware Inventory Import staging table in ServiceNow with a remove opcode. The scoped application then updates the state field of the Virtual Machine instance record in the CMDB to Terminated.
Cleanup steps:
- Create a scheduled script execution
- Navigate to Scheduled Script Executions (
sysauto_script) in the Global Scope. - Create a new record.
- Set the Run option to On Demand.
- Add the cleanup script
- Paste the following script into the Script field:
var vmi = new GlideRecord('cmdb_ci_vm_instance');
vmi.addEncodedQuery('discovery_source=FlexeraOne^state=terminated');
vmi.query();
while (vmi.next()) {
vmi.setWorkflow(false); // Disable business rules/workflows for this record
vmi.deleteRecord(); // Delete the current record
}
- Execute the script
- Save the record.
- Click Execute Now.
- Validate cleanup
- Check the Progress Worker to confirm the script has completed.
- Verify that all records in the
Virtual Machine Instancestable with the following values have been deleted: Discovery source = Flexera OneState = Terminated
After the script completes, all terminated virtual machine instance records originating from Flexera One will be removed from the ServiceNow CMDB, helping maintain alignment between Flexera One inventory data and ServiceNow configuration records.