
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2018 09:39 AM
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.
- Open a deleted record that you want to restore.
Note: You can only restore one deleted record and its associatd references at a time.
- 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 RecordI 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.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2018 09:50 AM
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!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2018 09:50 AM
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2018 07:41 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2018 07:50 AM
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2019 10:27 AM
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