Refactor Duplicate Records for any table script and Add Dynamic output support#1947
Merged
ravichandra1998g merged 2 commits intoServiceNowDevProgram:mainfrom Oct 8, 2025
Conversation
Enhancements
Function name changed from DupCheck to findDuplicateRecords for clarity.
Variable arr renamed to outputValues to better reflect its purpose.
Variable gr renamed to aggregateGR for clearer context.
Variable kb renamed to recordGR to remove table-specific implication.
HTML entity > replaced with '>' in the addHaving clause.
Use of addQuery('active', 'true') replaced with addActiveQuery() for standard filtering.
Field access changed from direct property access (e.g. kb.number) to getValue() for consistency.
Array logging improved by using JSON.stringify(outputValues) for readability.
Hardcoded usage moved to a clearly marked section for easier customization.
Added Functionality
New parameter outputFields added to allow dynamic specification of which fields to include in the output.
Each output entry is now a key-value object containing values from the specified outputFields.
Logging per duplicate record now reflects the full output entry using JSON.stringify(outputEntry).
Updated the Readme file to reflect enhancement to the script. In addition, made it clear that there are 2 scripts (which was already the case). And per script explained the functionality in more detail. Including that of the original single script.
ravichandra1998g
approved these changes
Oct 8, 2025
Contributor
ravichandra1998g
left a comment
There was a problem hiding this comment.
There seems to be multiple scripts for finding duplicate records, but this one is supporting dynamic output! Thank you for submitting!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Description:
This pull request updates two files:
readme.md: Updated the readme to describe both scripts: existing "Duplicate records.js", and the refactored "Duplicate Records for any table based on field.js".
Duplicate Records for any table based on field.js: Refactored the original script to support any table and field, introduced dynamic output fields via a new parameter, replaces hardcoded logic with reusable components, and improved logging and readability. Variable naming is updated to reflect the 'any table' nature of this script. The old one contained references to kb.
Pull Request Checklist
Overview
Code Quality
Repository Structure Compliance
Note: Kept existing file structure, as this is only updating the 2 files in the already existing structure.
Core ServiceNow APIs/Server-Side Components/Client-Side Components/Modern Development/Integration/Specialized Areas/Documentation
Restrictions