-
Notifications
You must be signed in to change notification settings - Fork 905
feature: Added Safe Bulk Record Update with Progress Tracking snippet #2569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: Added Safe Bulk Record Update with Progress Tracking snippet #2569
Conversation
|
hey @ravichandra1998g please review this |
SapphicFire
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution. The idea is great, but there are some changes that need to occur before we can accept it. I will leave this open for a day :)
| while (gr.next()) { | ||
| recordsToProcess.push(gr.getUniqueValue()); | ||
|
|
||
| // Process in batches to prevent timeout |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As these updates are occurring within the same execution, this does not prevent timeout or create separate items to process in parallel
| var errorCount = 0; | ||
| var totalProcessed = 0; | ||
|
|
||
| gs.log('[Bulk Update Started] Table: ' + TABLE + ' | Filter: ' + FILTER, 'BulkUpdate'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gs.log usage is not recommended
| var record = new GlideRecord(TABLE); | ||
| record.get(recordIds[i]); | ||
| record.setValue(FIELD_TO_UPDATE, NEW_VALUE); | ||
| record.update(); | ||
| successCount++; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are doing 100 database queries instead of one for all 100 records, and updating one at a time instead of using updateMultiple. This is not ideal. Consider changing this to iterate through all of the records to reduce the queries, and consider updateMultiple to reduce the database updates
| - [GlideRecord Query API](https://docs.servicenow.com/bundle/sandiego-application-development/page/app-store/dev_apps/concept/c_UsingGlideRecord.html) | ||
| - [GlideSystem Logging](https://docs.servicenow.com/bundle/sandiego-application-development/page/app-store/dev_apps/concept/c_SystemLog.html) | ||
| - [Best Practices for Bulk Operations](https://docs.servicenow.com/bundle/sandiego-application-development/page/app-store/dev_apps/concept/c_BulkOperations.html) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These docs are very out of date and not accessible anymore, how did you get these links?
|
@SapphicFire Really appreciate your time! You’re meticulous, which is a great trait for a developer — I’ll definitely learn that from you. I made a few changes: used gs.info() instead of gs.log() and applied updateMultiple(). Please let me know if there’s anything else I should improve. |
Removed example usage, key features, output examples, performance notes, customization, requirements, and related APIs sections from the README.
|
i think u can merge now.. |
SapphicFire
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me
PR Description:
small summary
Background Script for safely updating multiple records with batch processing,
error handling, and progress tracking to prevent timeouts.
What i did
the Features are
What it does: Updates many records safely with error handling and progress logging
Why needed: Shows best practices for bulk operations without timeout
Pull Request Checklist
Overview
Code Quality
Repository Structure Compliance
Core ServiceNow APIs/Server-Side Components/Client-Side Components/Modern Development/Integration/Specialized Areas/Documentation
Restrictions