Regarding Rollback deleted records by using condition created on

sivakumaraa
Giga Contributor

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:

var del = new GlideRecord('sys_audit_delete');
del.addQuery('sys_updated_on', 'ON ', '2026 - 05 - 20 ');
del.query();
while (del.next()) {
    var rollback = new GlideRollback();
    rollback.rollbackSequence(del);
    gs.print('Rolled back sequence: ' + del.sys_id);
}
gs.print(' Error Rolled back sequence: ' + del.sys_id);
 
can you please modify and update the script
9 REPLIES 9

Tanushree Maiti
Tera Patron

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:

Screenshot 2026-05-31 021409.png

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);
}

 

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

@Tanushree Maiti script is not working

Hi @sivakumaraa 

 

Add gs.print statement and let me know which line is not working.

 

Hope you have deleted data for 20-05-2026 .

 

 

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

Ankith Sharma
Tera Guru

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