Skip to content

Conversation

@spnegi
Copy link
Contributor

@spnegi spnegi commented Oct 6, 2025

PR Description:

Bucket Group Age Calculation - This calculates the bucket group age calculation. This helps us to run this scheduled job and allow to put bucket level aging on every record and it allows to create the reports on table level.

Pull Request Checklist

Overview

  • I have read and understood the CONTRIBUTING.md guidelines
  • My pull request has a descriptive title that accurately reflects the changes
  • 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

Copy link
Contributor

@WillemZeiler WillemZeiler 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 submission. I have added comments for you to review and adjust. Please expand the readme. As it is not clear at the moment what the added value of this script is versus OOTB reporting and SLA capabilities. Closing this for now. Feel free to submit a PR with the changes.

@@ -0,0 +1,24 @@
var rec = new GlideRecord('case'); // any table which you want to use
rec.addEncodedQuery('stateNOT IN60,40, 20'); // filtering out all the closed/cancelled cases
Copy link
Contributor

Choose a reason for hiding this comment

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

Active = true or addActiveQuery is better. If you want to stick with this, explain in the comment what states 60, 40, 20 are exactly.

var openedDate = new GlideDateTime(rec.opened_at.getDisplayValue());
var dur = GlideDateTime.subtract(openedDate,actualDateTime );
//gs.info("dur"+dur.getNumericValue()) ;
elapsedTime = dur.getNumericValue()/86400000 ;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not a defined variable. Define it first.

while (rec.next()) {
var openedDate = new GlideDateTime(rec.opened_at.getDisplayValue());
var dur = GlideDateTime.subtract(openedDate,actualDateTime );
//gs.info("dur"+dur.getNumericValue()) ;
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove commented out logs or explain if users can add it back in to add functionality.


rec.setWorkflow(false); // Skip any Business Rules
rec.autoSysFields(false); // Do not update system fields
rec.aging_category = aging;
Copy link
Contributor

Choose a reason for hiding this comment

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

aging is not defined anywhere. Declare it before using it.

elapsedTime = dur.getNumericValue()/86400000 ;
// gs.info ("elapsedTime" + elapsedTime)
// Check to see when the item was created
if (elapsedTime <= 2) aging = '0-2 Days';
Copy link
Contributor

Choose a reason for hiding this comment

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

aging is not defined anywhere. Declare it before setting it's value.

@@ -0,0 +1 @@
Find out all the cases with the difference in their create date and current date and put them in different buckets of their age. Then you can report on the aging. With this you will be able to run the Bucket Group reporting on tables without using PA.
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the benefit of these buckets? Why not create a report on the Case SLA for example?

@spnegi
Copy link
Contributor Author

spnegi commented Oct 6, 2025

Sure. I will work on it. Can you help me opening this request?

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.

3 participants