In alm hardware table, we have 7000 records and all records have ci linked to it on cmdb_ci_computer, i want to delete all records from hardware and computer table and cmdb ci boths in servicenow
Assistant
Deleting records from the alm_hardware table, the cmdb_ci_computer table, and the corresponding Configuration Items (CI) in the cmdb_ci table in ServiceNow requires careful handling to avoid data loss or unintended consequences. It's crucial to ensure you have the necessary administrative privileges and have performed sufficient backups before proceeding.
Here's a high-level approach to achieve this through ServiceNow. This process can be executed using a business rule, script include, or background script depending on how you want to manage the operation.
Step-by-Step Guide:
Backup Data:
Always start by exporting the data from the alm_hardware, cmdb_ci_computer, and cmdb_ci tables to a CSV or XML file so you can restore your data if anything goes wrong.
Identify Records:
Identify the ci entries linked to alm_hardware records that you want to delete.
Delete Records:
Write a script that deletes the alm_hardware entries, also ensuring that linked ci entries in cmdb_ci_computer and cmdb_ci are deleted.
Script for Deleting Records:
Here is an example of a script you can run in the Scripts - Background module (System Definition > Scripts - Background):
javascript
// Start by confirming you have backup and proper administration rights
(function() {
var grALM = new GlideRecord('alm_hardware');
grALM.query();
gs.print("Starting deletion process...");
while (grALM.next()) {
// Get the CI sys_id linked to alm_hardware record
var ciSysId = grALM.cmdb_ci + '';
// Delete the alm_hardware record
grALM.deleteRecord();
// Now, delete the CI records in cmdb_ci_computer and cmdb_ci tables
if (ciSysId) {
// Delete from cmdb_ci_computer
var grCIComputer = new GlideRecord('cmdb_ci_computer');
if (grCIComputer.get(ciSysId)) {
grCIComputer.deleteRecord();
gs.print('Deleted from cmdb_ci_computer: ' + ciSysId);
}
// Delete from cmdb_ci, if needed
var grCI = new GlideRecord('cmdb_ci');
if (grCI.get(ciSysId)) {
grCI.deleteRecord();
gs.print('Deleted from cmdb_ci: ' + ciSysId);
}
}
}
gs.print("Deletion process completed.");
})();
Post-Script Steps:
Validation:
Validate the deletions by querying the alm_hardware, cmdb_ci_computer, and cmdb_ci tables to ensure the records are successfully removed.
Audit Logs:
Check the audit logs in ServiceNow to ensure that all deletions are accounted for, and there are no unexpected changes.
Notes:
Ensure you have appropriate permissions to delete records from these tables.
Consider running the script in a sandbox instance before running it in the production environment.
Use Transaction Quotas and Batch processing if dealing with a large dataset to ensure system performance is not impacted.
Alternatively, contact your ServiceNow administrator or ServiceNow support for assistance if you're unsure about the script execution.
This script should be used with caution as it will permanently delete records from your ServiceNow environment. Always have backups and a rollback plan.