Delete Asset but leave CI
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2025 01:06 AM
Hi Expert
I have requirement to delete the Asset and not CI whenever Asset state is "Retired" and substate is "Delete". I have written a script for the same. However, it is deleting Asset as well as also deleting the CI. Please suggest what modification I will do so in the below script to delete only Asset not CI.
Script:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2025 01:47 AM
The asset is deleted as the reference field has cascade delete enabled. Some would recommend to use setWorkflow(false) to prevent this behaviour, however that has other consequences. Ideally you'd archive and then delete records...rather than GR deleting.
But the following would be an option
var deleteAsset = new GlideRecord('alm_hardware');
deleteAsset.addEncodedQuery('install_statusIN7^substatus=Delete');
deleteAsset.query();
var util = new AssetandCI()
while (deleteAsset.next()) {
util.deleteAssetOnly(deleteAsset);
}