Run Scheduled job in batches to update all records in a table

Sumanthkumar1
Tera Contributor

I have one custom table which has 5 million records, I need to populate few fields from out of box table to this custom table with a scheduled job. The requirement is to run job on batches to reduce the performance issues. Please suggest a code to run a schedule job as batches with limit 1000 records at a time and take 10 seconds pause after every run.

3 REPLIES 3

Astik Thombare
Tera Sage

Hi @Sumanthkumar1 ,

 

Please refer below blog -

 

https://snprotips.com/blog/2018/10/11/how-to-do-massive-slow-database-operations-without-slowing-dow...

 

If my reply helped with your issue please mark helpful 👍 and correct ✔️ if your issue is resolved.

 

                          By doing so you help other community members find resolved questions which may relate to an issue they're having

 

 

Thanks,

Astik

 

Community Alums
Not applicable

You can try the Data maintenance update records module.  You can apply a filter to return a number of records updated in the batch and then schedule when it will update all the records. It will analyze to see all the recursive records it will update so that you get the scope of how large the update will be. Then you can execute it on demand or via schedule and it will run in the background.  If there's a mistake with an update then you restore from backup that will be made prior to the update. This is an all no code solution.  I've done it to thousands of records at a time before

Omkar Mone
Mega Sage

Hello,

 

I had done something similar which I had shared sometime back. Please check this - https://www.servicenow.com/community/developer-blog/optimizing-servicenow-achieving-scale-with-multi...