Use a cleanup script to remove VM instance records in Flexera One ServiceNow app 1.7
This article explains how to run a cleanup script to remove unnecessary VM records if you have been using version 1.6 or 1.7 of the Flexera One ServiceNow app before the 1.7 patch release and have VM instance records sourced from the IT Visibility Hardware Inventory API.
The cleanup script removes all VM records created by the FlexeraOne app in the cmdb_ci_vm_instance table. These records represent Guest VMs, not VM instances, and therefore should reside under the Computer/Server hierarchy within the CMDB. Removing them ensures that during the next snapshot run, the Classification Rules Framework correctly maps and classifies guest VM data into the appropriate CI classes. The version 1.7 patch fixes the mapping logic, but does not remove the existing records in the cmdb_ci_vm_instance table.
Clean up VM instances
-
Create a new Scheduled Script Execution (sysauto_script) record in the Global scope and name the record: FlexeraOne job to remove VM from VMI table.
-
Set the Run option to On Demand.
-
In the Script field, add the following cleanup script:
var deletedCount = 0;
var guestVM = new GlideRecord('cmdb_ci_vm_instance');
guestVM.addQuery('discovery_source', 'FlexeraOne');
guestVM.query();
while (guestVM.next()) {
guestVM.deleteRecord();
deletedCount++;
}
gs.info('[Cleanup Job] Deleted ' + deletedCount + ' VM records from cmdb_ci_vm_instance where discovery_source=FlexeraOne');
-
After entering the script and configuring required fields, select Save.
-
Click Execute Now to run the script.
-
Monitor script progress:
-
-
Navigate to System Scheduler > Progress Worker to track the execution status.
-
-
-
You can also monitor System Logs > System Log > All for entries from the script. Look for log entries like:
[Cleanup Job] Deleted X VM records from cmdb_ci_vm_instance where discovery_source=FlexeraOne
-
-
Validate the cleanup:
-
-
Navigate to the cmdb_ci_vm_instance table.
-
-
-
Apply the filter: discovery_source=FlexeraOne
-
-
-
Confirm that no records are returned. This result indicates the cleanup was successful.
-
-
Run the Snapshot Job.