How can I restore mass records in ServiceNow which is deleted by mistake?

Sontel
Tera Contributor

I was removing choices from a variable and there were 250+ choices, so I thought to use a script which ended up deleting everything from the table Question_choices.I've deleted all the 15K choices from Question_choices table mistakenly. When I checked for the restore option, I didn't find anything which can restore all the records in one go. I found this solution on another thread on the community:

Navigate to System Definition > Deleted Records.

  1. Open a deleted record that you want to restore.
    Note: You can only restore one deleted record and its associatd references at a time.
  2. In the Audit Deleted Record form, select Restore Record and References under Related Links.
    Note: To restore the record without restoring the references, select Undelete Record
     
    I selected 100 records at a time in list view and restored everything. My question here is how can I do it in less time as restoring 15K records with this option took me 2 hours. Is there any other way we can do it.
     
    Note of caution - Please read all the follow-up comments before running the script from Correct Answer, as it has syntax error that may cause issues if you run without correcting it.
1 ACCEPTED SOLUTION

Allen Andreas
Tera Patron

I would say that you should stay away from scripts given what has happened...but...lessons aside: Try this in a background script...you'd need to fix your encodedquery to grab what you're looking for.

var deleted = new GlideRecord('sys_audit_delete');


deleted.addEncodedQeury('put query here');


deleted.query();


while(deleted.next()){


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


}

Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

11 REPLIES 11

I'm unable to edit the post and if you read through this all the way, you'd have seen the correction and my acknowledgement.

Sorry for the trouble that was caused, but this could have been avoided if you read all the way.

We should be appreciative enough for the help that was given in the first place.

Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

How to Thank you Allen ! You always turn out to be savior. It was such a tedious task and I was searching for scripts. Thank you so much !!

chandu-snow
Mega Contributor

Allen - I have similar request and I'm trying to restore 700,000 records - how long does it take, if i schedule this  in Schedule Job?

 

Thanks!

Mike Cornell
Tera Contributor

Content Admin: We might want to take consider taking this post down and restore it elsewhere... some people are reading quickly and don't read through all the comments.  I know of a company recently that ran this script on their own environment and caused a massive restore problem -- because of the wrong syntax it ignored the filter altogether.  This post is a bit of a liability I think...

Hi @Mike Cornell I have edited and added a Note of Caution in the original post for anyone coming across this post. Thanks for highlighting this concern to avoid blunders for other seekers.