Background script to delete records
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2024 01:17 PM
Hi All,
Have a requirement to delete empty rows from sys_user table. There are massive no of empty records based on conditions(encoded query)and when trying to delete its hanging.
Please suggest script to delete say 1000 or 2000 records from the list and then run the script again to delete next batch.
TIA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2024 10:20 PM
Hello @CV1
I would suggest to use glidemultipledelete API as there are no requirement to delete associated records and hence this method is super fast.
var md = new GlideMultipleDelete("sys_user");
md.addQueryString('Query');
md.execute();
gs.info('Records deleted successfully');
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,
CB
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2024 10:28 PM
try to use setLimit() and delete in chunks
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader