Delete Records

alvatindra
Giga Contributor

Hi All,

I have created update set and created table which extends CMDB.

I have created the records in the new table.

I have backouted the update set. Table is deleted and everything related to that like business rules were gone.

But the records which I have created in the new table are still present under the cmdb table with Class as label.

The problem here is the records which I have created in new table are not getting deleted from the cmdb table.

Please anyone help me, I tried to delete the records from the background script but didnt worked.

9 REPLIES 9

Chuck Tomasi
Tera Patron

It sounds like your table was deleted, but the table relationship may have gotten disrupted somewhere. There's always going to be a sys_id at the parent class to join with the rest of the record at the child class.



How many records are there? If it is less than 100, I'd just use the list to check them and delete them.



If it's lots of records then see if you can filter the cmdb table list to just the records you want to delete and copy the query in to a script you have in scripts background. This should help if you haven't don that before.



Video: Scripting Complex Queries Quickly


Hi chuck,



I tried with background scripts, and also with the checkbox, they are not deleting. There are less than 1000 records



Thanks,


If this is your corporate instance, then I recommend reaching out to support. They may have to do something at the database level.



HI Service Portal - ServiceNow


Contact Support | ServiceNow


sachin_namjoshi
Kilo Patron
Kilo Patron

Please use below code to delete record and it's references in corresponding tables.



//Find all non-active incident records and delete them


var md = new Packages.com.glide.db.MultipleDelete('incident');


md.addQuery('active', false);


md.setAllowCascadeDelete(); // optional: Allow cascading to records in other tables related to records being deleted


md.execute();



Regards.


Sachin