Best Practice : Record Deletion
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2023 08:35 AM
Hello Experts,
I want delete records from a table which are older than 30 days . I want to have records of only last 30 days and not older than that.
I want to the perform this action every week on Sunday. what could be the best practice to implement the above scenario.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2023 08:43 AM
You should look at Table Rotation -> Check this link Demystifying table rotation, extension, and table ... - ServiceNow Community

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2023 09:12 AM
Hi,
You could set up a simple scheduled Flow to regularly delete old records.
Simple example below.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2023 09:22 AM
Hi @Abc 26 ,
I trust you are doing fine.
To delete records from a table that are older than 30 days, you can create a scheduled job that runs a script to delete the records. Here's an example script that you can modify to fit your specific table name and field for date tracking:
var daysAgo = new GlideDateTime();
daysAgo.addDays(-30);
var query = 'sys_created_on<'+daysAgo.getValue();
var gr = new GlideRecord('your_table_name_here');
gr.addQuery(query);
gr.deleteMultiple();
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi