- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2025 09:51 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:
Solved! Go to Solution.
- Labels:
-
Asset Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2025 03:34 AM
Hi @JeetBaliarsingh,
Please see the above updated script for you to test.
To help others (and for me to gain recognition for my efforts), please mark this response correct by clicking on Accept as Solution and/or Kudos.

Thanks, Robbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2025 10:00 AM - edited ‎04-25-2025 03:32 AM
Hi @JeetBaliarsingh,
(Updated)
Can you add the following syntax leveraging deleteAssetOnly() method available with the AssetandCI class.
Please test this in a non Prod / Dev environment first before running on live data.
var deleteAsset = new GlideRecord('alm_hardware');
deleteAsset.addEncodedQuery('install_statusIN7^substatus=Delete');
deleteAsset.query();
while (deleteAsset.next()) {
var assetAndCI = new AssetandCI();
assetAndCI.deleteAssetOnly(deleteAsset);
}
ServiceNow support article for deleteAssetOnly() - https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0823993
You may also want to consider using the .deleteMultiple() method for performance efficiencies as advised here:
To help others (and for me to gain recognition for my efforts), please mark this response correct by clicking on Accept as Solution and/or Kudos.

Thanks, Robbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2025 01:02 AM
Hi Robbie
Thanks for your response. However, what you are suggesting is not my ask. See asset and CI are linked with each other. When you delete the Asset, associated CI will also get deleted. Here using script I want to delete the Asset but associated CI shouldn't be deleted.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2025 03:34 AM
Hi @JeetBaliarsingh,
Please see the above updated script for you to test.
To help others (and for me to gain recognition for my efforts), please mark this response correct by clicking on Accept as Solution and/or Kudos.

Thanks, Robbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2025 03:55 AM
Hi Robbie
Thank you for your proactive response. It is working fine now.