Skip to content

Conversation

@bird-03
Copy link
Contributor

@bird-03 bird-03 commented Oct 5, 2025

PR Description:

This is script will be useful to montior your system performance by identifying the top contributors from schedule jobs by processing time to take necessary action.

In this script time intervalis updated as last 15 min but in ideal scenario this should be scheduled everyday to get the count report and montior the schedule job that is take more time to get completed.

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

Identify top 10 contributors from schedule jobs by processing time
This is script will be useful to montior your system performance by identifying the top contributors from schedule jobs by processing time to take necessary action. 

In this script time intervalis updated as last 15 min but in ideal scenario this should be scheduled everyday to get the count report and montior the schedule job that is take more time to get completed.
@WillemZeiler WillemZeiler self-assigned this Oct 5, 2025
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. Please double check your code. I have added some comments to guide you.

gr.setLimit(10);
gr.query();
while (gr._next()) {
responseTime.push(gr.response_time.toString());
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 using glideAggregate, should this be a glideRecord instead? As you want to use setLimit and get the value of response_time for 10 records only

var stdout = [];
var responseTime = [];
stdout.push('\nTop ' + pCount + ' ' + pColumn + ' values from ' + pTable + '\n');
while (ga.next() && (i++ < pCount)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a comment here to explain what you are doing and why? This will help others understand. Perhaps even easier: give an example output in the readme.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

var gr = new GlideAggregate(table);
gr.addEncodedQuery(query);
gr.orderByDesc('response_time');
gr.setLimit(10);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are you using 10 hardcoded here and in the rest of the code the pCount?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

to get the number of execution a particule job has been executed for given query Eg. last 15 min

var ga = new GlideAggregate(pTable);
ga.addAggregate('COUNT', pColumn);
ga.orderByAggregate('COUNT', pColumn);
//ga.addEncodedQuery('sys_created_onONYesterday@javascript:gs.beginningOfYesterday()@javascript:gs.endOfYesterday()^type=scheduler');
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 code. If this is an optional line people can enable, please describe it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@WillemZeiler
Line-9 has been commented on purpose to not run this script for all records executed yesterday as 'syslog_transaction' is a system table that stores logs for various transactions in the platform. This is kept and commet to give an option to schedule this script if required and can run every night out-of-business hours to get the list of top 10 contributors by type 'scheduler'.

Hope this help, if still needs to be remove happy to do that

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