How to Retrieve large number of deleted records

vtred
Tera Contributor

Management asked me to deleted 10,000 Records and now they want them back.

I went to Deleted Records module and saw the records exist: but here, its hard to keep selecting 200 records at once and undelete the records.

Is there any other way to retrieve all those records at once?

7 REPLIES 7

Nate23
Mega Guru

you can build your query in a fix script and run it.



var deleted = new GlideRecord('sys_audit_delete');


deleted.addEncodedQeury('paste your query here from your breadcrumbs on the deleted table');


deleted.query();


while(deleted.next()){


new GlideAuditDelete().undelete(deleted.sys_id);


}


just know this code is untested and to always test on a subset of records in your non-prod environment



also this code restores the deleted record(s) but does NOT restore references or relationships


nagydan2
Tera Contributor

LOOK OUT! WARNING!

 

Nate: your code has a typo, that will cause to restore all kinds of records, just not the one in the query.

Your code says: "addEncodedQeury"

Correct code is: "addEncodedQuery"

 

adilrathore
ServiceNow Employee
ServiceNow Employee

Restoring deleted records comes under Table Administration. There are several methods for restoring deleted records:



Check this link for details:



https://docs.servicenow.com/bundle/helsinki-servicenow-platform/page/administer/table-administration...



Please mark as Answered if your query is resolved.