Need to delete a Mass number of Assets but not the associated CIs

Sreeja3
Giga Contributor

Hi Developers,

I have a requirement to delete assets for some specific Model Categories but the associated CIs with the assets should not be deleted.

I can see "Delete asset only" UI action on "alm_hardware" table but we have to delete a lot of records so its impossible to go in every records and delete that manually.

I tried to delete that by a Scheduled Job but checked that CIs are also deleting with it.

Here is my script

var gr = new GlideRecord('alm_asset');

gr.addEncodedQuery('model.sys_id=42819a63db8da3c055077608f49619b3'); // product model sys_id

gr.query();

while (gr.next()){

gr.deleteMultiple();
}

Can anyone please help me with the script where CIs should not be impacted while deleting the assets. Any help would be appreciated. 

 

Regards,

Sreeja

1 ACCEPTED SOLUTION

joaof
Mega Expert

Go to cmdb_ci dictonary and open Asset field, then add Reference cascade rule field to the dictionary view, its default value should be Delete, change it to None temporarily and save it.

Delete the necessary assets and change Reference cascade rule to Delete again afterwards.

View solution in original post

3 REPLIES 3

joaof
Mega Expert

Go to cmdb_ci dictonary and open Asset field, then add Reference cascade rule field to the dictionary view, its default value should be Delete, change it to None temporarily and save it.

Delete the necessary assets and change Reference cascade rule to Delete again afterwards.

Sreeja3
Giga Contributor

Hi Joaof,

Thanks for your response. I tried to edit the reference cascade rule on cmdb_ci table but it redirects me to CMDB table. Should I proceed with it?

Regards,

Sreeja

Hi Sreeja,

This page is read-only by default, try clicking on the link to edit it. You can (and should) set it back to Delete once deletion is complete. Please see screenshot.
And yes, it'll redirect you to the Base Configuration Item [cmdb].

find_real_file.png