Skip to content

Conversation

@bird-03
Copy link
Contributor

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

PR Description: Find out the groups that are inactive and not updated in last 6 months. Print the group names as a comma seprated array .

This schedule script will execute monthly, weekly or bi-weekly as frequency is scheduled to identify all the groups that are not referenced in any Task(INC/PRD/CHG/RITM) in last 6 month and mark them INACTIVE.

This activity has been carried out as cleanup activity for groups that are not in use and consuming license role

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

This schedule script will execute monthly, weekly or bi-weekly as frequency is scheduled to identify all the groups that are not referenced in any Task(INC/PRD/CHG/RITM) in last 6 month and mark them INACTIVE. 

This activity has been carried out as cleanup activity for groups that are not in use and consuming license role
This schedule script will execute monthly, weekly or bi-weekly as frequency is scheduled to identify all the groups that are not referenced in any Task(INC/PRD/CHG/RITM) past 6 months for analysis and inactivate them after analysis

What it does and how it can add value ?
 - Find out the groups that are inactive and not updated in last 6 months. Get the group names as a comma seprated array 
 - Check if the group has any task assigned in the last 6 months (tasks that were created after the date 6 months ago.)
 - Get the list as Output of all inactive group names as a comma-separated string

Benifits:
This activity has been carried out as cleanup activity for groups that are not in use and consuming license role
@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. I have added comments to the script. Feel free to make the requested adjustments and re-submit the PR. For now I will close this PR.

@@ -0,0 +1,9 @@
This schedule script will execute monthly, weekly or bi-weekly as frequency is scheduled to identify all the groups that are not referenced in any Task(INC/PRD/CHG/RITM) past 6 months for analysis and inactivate them after analysis
Copy link
Contributor

Choose a reason for hiding this comment

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

You cannot inactivate an inactive group. Can you update this description? What is it you are doing with the Inactive group array? From the code it is a list of inactive groups, that have no tasks assigned. What about inactive groups that have tasks assigned?

var groupName = grGroups.getValue('name');

// Check if the group has any task assigned in the last 6 months
var taskCheck = new GlideAggregate('task');
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 looking through all tasks, closed or open, why is that? An inactive group with closed tasks to it's name would still be inactive, correct? So perhaps add a check for open tasks or closed in the past 6 months?

var inactiveGroups = [];

var grGroups = new GlideRecord('sys_user_group');
grGroups.addInactiveQuery(); // To find all groups that are Active = False in sys_user_group table
Copy link
Contributor

Choose a reason for hiding this comment

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

Combination of line 7 + 8 does not work or is not needed, as this will just return all records.
It would make sense to only look at Active groups, that do not have any open tasks for the past 6 months.

- Get the list as Output of all inactive group names as a comma-separated string

Benifits:
This activity has been carried out as cleanup activity for groups that are not in use and consuming license role
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a disclaimer as licence consumption is something to be cautious in making statements about. You are not covering all groups that are active in the system, but should be inactive. F.e. there could be an assignment done to an Active tasks to a team that is now not in use anymore. With a disclaimer it will help people to understand it is an helpful tool, but no guarantees.

// Check if the group has any task assigned in the last 6 months
var taskCheck = new GlideAggregate('task');
taskCheck.addQuery('assignment_group', groupSysId); //filter to only include tasks where the assignment group matches the current group's sys_id.
taskCheck.addQuery('sys_created_on', '>', sixMonthsAgo); //filter to only include tasks that were created after the date 6 months ago.
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 think of a way to make the six months lookback variable? Different companies/teams might have a different definition of inactive. f.e. 3 moths or 9 months etc.

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