Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
var sixMonthsAgo = new GlideDateTime();
sixMonthsAgo.addMonthsUTC(-6);

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.

grGroups.addActiveQuery(); // To find all groups that are Active = True in sys_user_group table
grGroups.query();

while (grGroups.next()) {
var groupSysId = grGroups.getValue('sys_id');
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?

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.

taskCheck.addAggregate('COUNT');
taskCheck.query();

//If the count is greater than 0, the group has task activity, so it's not inactive.

var isInactive = true;
if (taskCheck.next()) {
var count = parseInt(taskCheck.getAggregate('COUNT'), 10);
if (count > 0) {
isInactive = false;
}
}

// Add only unique group names
if (isInactive && inactiveGroups.indexOf(groupName) === -1) {
inactiveGroups.push(groupName);
}
}

// Output all inactive group names as a comma-separated string

if (inactiveGroups.length > 0) {
    var groupArrayString = '["' + inactiveGroups.join('", "') + '"]';
    gs.log('Inactive groups (last 6 months) as array: ' + groupArrayString);
} else {
    gs.log('No inactive groups found in the last 6 months.');
}
Original file line number Diff line number Diff line change
@@ -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?


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
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.

Loading