Skip to content

Conversation

@hanna-g-sn
Copy link
Contributor

PR Description:

This submission demonstrates an efficient use of GlideRecord, GlideDateTime, and GlideSystem to find and process records older than a configurable threshold (N days) without heavy queries.

Use case:
Identify and act on aged records (for example, Incidents older than 30 days) in a performance-safe way.

Key features:

  • Uses GlideDateTime arithmetic for UTC-safe date boundaries
  • Encoded query keeps index usage optimal
  • Supports sampling with setLimit for background testing

Includes:

  • README.md explaining use, setup, and links to official documentation
  • gr_older_than_n_days.js ready to run as a Background Script or Script Include method

Tested in:
Zurich release instance on incident table with 5k records. Verified count output and date filter accuracy.

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

This README provides a guide on querying records older than a specified number of days using GlideRecord in ServiceNow. It includes details on the solution, usage context, implementation steps, and references to relevant APIs.
This script retrieves records from the 'incident' table that are older than 30 days based on the 'opened_at' field. It limits the output to 200 records and provides a count of the retrieved records.
@ravichandra1998g ravichandra1998g self-assigned this Oct 21, 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.

Hello @hanna-g-sn
We appreciate the effort you’ve put into this contribution.

For Hacktoberfest, we’re aiming for high-quality contributions providing real-world use developer cases. You can see some of the recently merged PRs to know the kind of code snippets we are aiming for.

This cannot be merged as the code snippet is basic Gliderecord query to get records along with GlideDateTime filter.

Please do not submit low effort PRs.

Please reopen/ submit a new one after adding more dynamic context/use cases that are more suitable for the Hactoberfest!

Thank you!

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