Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Delete Asset but leave CI

Prasnajeet1
Giga Guru

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:

var deleteAsset = new GlideRecord('alm_hardware');
deleteAsset.addEncodedQuery('install_statusIN7^substatus=Delete');
deleteAsset.query();
 
while (deleteAsset.next()) {
    deleteAsset.deleteRecord();
}
1 REPLY 1

Kieran Anson
Kilo Patron

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);
}