Skip to content

Refactor Duplicate Records for any table script and Add Dynamic output support#1947

Merged
ravichandra1998g merged 2 commits intoServiceNowDevProgram:mainfrom
WillemZeiler:improvement/code-and-comment
Oct 8, 2025
Merged

Refactor Duplicate Records for any table script and Add Dynamic output support#1947
ravichandra1998g merged 2 commits intoServiceNowDevProgram:mainfrom
WillemZeiler:improvement/code-and-comment

Conversation

@WillemZeiler
Copy link
Contributor

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

  • 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

Note: Kept existing file structure, as this is only updating the 2 files in the already existing structure.

  • 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

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 ravichandra1998g self-assigned this Oct 8, 2025
Copy link
Contributor

@ravichandra1998g ravichandra1998g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be multiple scripts for finding duplicate records, but this one is supporting dynamic output! Thank you for submitting!

@ravichandra1998g ravichandra1998g merged commit d49aa0f into ServiceNowDevProgram:main Oct 8, 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