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
Administrator
Administrator

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

10 REPLIES 10

Allen Andreas
Administrator
Administrator

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!

Please note there is a spelling mistake in the above script 

deleted.addEncodedQeury('put query here');

should be 

deleted.addEncodedQuery('put query here');

That script as it stands would restore ALL previously deleted records

Thanks. I'm unable to edit the post, but good call out.


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

Please,

correct the method call:

deleted.addEncodedQeury('put query here');

should be:

delete.addEncodedQuery('...');

 

I copied this error and it caused me a lot of trouble.

 

Thanks