Need to delete all records in sys_audit_delete table older 1 year
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2024 02:35 AM
Hi All,
I need to delete all records in the table 'sys_audit_delete' older 1 year. Please help me..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2024 02:41 AM
Here is the script for the same
You can enter the date as you want, and all the records which are created before that date will be deleted:
var gr = new GlideRecord('sys_audit_delete');
gr.addEncodedQuery("sys_created_on<javascript:gs.dateGenerate('2023-02-28','00:00:00')); //Enter the date here
gr.query();
gs.info(gr.getRowCount());
while(gr.next()){
gr.deleteRecord();
}
If my response helps you in any way, please mark my response as helpful or "Accept as Solution" so that your question will help others as well
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2024 02:51 AM
Hello @pavankumar970 ,
Adapt the query as your needs with filter builder, and then copy the query in this script (be sure that the query retrieves the data that you need before removing):
var grAudit = new GlideRecord('sys_audit_delete');
grAudit.addEncodedQuery('sys_updated_on<=javascript:gs.beginningOfLast12Months()');
grAudit.query();
grAudit.deleteMultiple();
I would use deleteMultiple() function for this purpose, I let you and explanation over this: https://www.servicenow.com/community/developer-articles/servicenow-glide-record-deleterecord-vs-dele...
☆ Community Rising Star 22, 23 & 24 ☆