Regarding Rollback deleted records by using condition created on
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi,
My question is how to retrieve the deleted records in incidents by using condition created on. But we need to use server side script like fix or background script, can you please give suggestion how to write script.
This is my script:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Hi @sivakumaraa
Try this:
Run the following script using Fix Scripts or Scripts - Background. Always test this in a non-production instance first.
Note: In script replace Var date as per the screen shot:
var del = new GlideRecord('sys_audit_delete');
var date = "sys_created_onON2026-05-20@javascript:gs.dateGenerate('2026-05-20,'start')@javascript:gs.dateGenerate('2026-05-20','end')";
del.addEncodedQuery(date);
del.query();
while(del.next())
{
new GlideAuditDelete().undelete(del.sys_id);
}
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
@Tanushree Maiti script is not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Hi @sivakumaraa
Add gs.print statement and let me know which line is not working.
Hope you have deleted data for 20-05-2026 .
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @sivakumaraa,
Before modifying the undelete logic further, I'd first verify whether records are actually being returned from sys_audit_delete for the specified date.
var del = new GlideRecord('sys_audit_delete');
del.addQuery('sys_created_on', '>=', '2026-05-20 00:00:00');
del.addQuery('sys_created_on', '<=', '2026-05-20 23:59:59');
del.query();
gs.print('Records found: ' + del.getRowCount());
while (del.next()) {
gs.print('Audit Delete Sys ID: ' + del.sys_id);
}
If the count is 0, then the issue may be with the query criteria rather than the undelete logic itself.
@Tanushree Maiti , would you agree that validating the records in sys_audit_delete, first would be a good troubleshooting step before proceeding with GlideAuditDelete().undelete()? I'm curious if you've seen cases where the undelete logic was correct but the query wasn't returning any matching records.
Regards,
Ankit Sharma