scheduled job to delete records based on condition
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā06-24-2024 07:07 PM
Hello All,
We have huge number of records in sys_user table that needs to be deleted based on filter. I want to run a scheduled job to delete say 1500 records a day till the condition is satisfied at 1am. Please see the screenshot and advise if this is good or any modifications needed.
TIA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā06-24-2024 07:22 PM
Hi @CV1 ,
The script looks okay.
I would suggest to update the addQuery with addEncodedQuery and try to log without once to check if the correct details are coming up.
var grInc = new GlideRecord('incident');
grInc.addEncodedQuery('your_encoded_query'); //from list view your can pull out this
grInc.setLimit(1500);
grInc.query();
gs.log("Deleting user Records: " + grInc.getRowCount());
//grInc.deleteMultiple();
Once verified that the total count is matching. Then you can uncomment the deleteMultiple() command and execute it in scheduled job.
Mark this as Helpful / Accept the Solution if this helps.