Skip to content

Conversation

@BEASTSHRIRAM
Copy link
Contributor

@BEASTSHRIRAM BEASTSHRIRAM commented Oct 28, 2025

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

  • bulk_update_with_progress.js - Production-ready bulk update implementation
  • README.md - Complete usage guide and customization examples

the Features are

  • Batch processing to prevent timeouts
  • Individual error handling
  • Progress logging every N records
  • Works with any table and filter
  • Tracks success/error counts

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

  • Put an x inside of the square brackets to check each item.
  • I have read and understood the CONTRIBUTING.md guidelines
  • My pull request has a descriptive title that accurately reflects the changes and the description has been filled in above.
  • I've included only files relevant to the changes described in the PR title and description
  • I've created a new branch in my forked repository for this contribution

Code Quality

  • My code is relevant to ServiceNow developers
  • My code snippets expand meaningfully on official ServiceNow documentation (if applicable)
  • I've disclosed use of ES2021 features (if applicable)
  • I've tested my code snippets in a ServiceNow environment (where possible)

Repository Structure Compliance

  • I've placed my code snippet(s) in one of the required top-level categories:
    • Core ServiceNow APIs/
    • Server-Side Components/
    • Client-Side Components/
    • Modern Development/
    • Integration/
    • Specialized Areas/
  • I've used appropriate sub-categories within the top-level categories
  • Each code snippet has its own folder with a descriptive name

Documentation

  • I've included a README.md file for each code snippet
  • The README.md includes:
    • Description of the code snippet functionality
    • Usage instructions or examples
    • Any prerequisites or dependencies
    • (Optional) Screenshots or diagrams if helpful

Restrictions

  • My PR does not include XML exports of ServiceNow records
  • My PR does not contain sensitive information (passwords, API keys, tokens)
  • My PR does not include changes that fall outside the described scope

@BEASTSHRIRAM
Copy link
Contributor Author

hey @ravichandra1998g please review this

@SapphicFire SapphicFire self-assigned this Oct 28, 2025
Copy link
Contributor

@SapphicFire SapphicFire left a 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
Copy link
Contributor

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');
Copy link
Contributor

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

Comment on lines 46 to 50
var record = new GlideRecord(TABLE);
record.get(recordIds[i]);
record.setValue(FIELD_TO_UPDATE, NEW_VALUE);
record.update();
successCount++;
Copy link
Contributor

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

Comment on lines 92 to 94
- [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)
Copy link
Contributor

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?

@BEASTSHRIRAM
Copy link
Contributor Author

BEASTSHRIRAM commented Oct 29, 2025

@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.

BEASTSHRIRAM and others added 2 commits October 29, 2025 09:29
Removed example usage, key features, output examples, performance notes, customization, requirements, and related APIs sections from the README.
@BEASTSHRIRAM
Copy link
Contributor Author

i think u can merge now..

Copy link
Contributor

@SapphicFire SapphicFire left a 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

@SapphicFire SapphicFire merged commit 54f39ce into ServiceNowDevProgram:main Oct 29, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants