From 8afecf31d12b6084ed63b77517eacdaf91d7f62a Mon Sep 17 00:00:00 2001 From: Abhishek Pandey <91930405+bird-03@users.noreply.github.com> Date: Mon, 6 Oct 2025 00:33:21 +0530 Subject: [PATCH 1/2] Create IdentifyInactiveGrp.js 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 --- .../IdentifyInactiveGrp.js | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Server-Side Components/Scheduled Job/inactiveGroupCleanup/IdentifyInactiveGrp.js diff --git a/Server-Side Components/Scheduled Job/inactiveGroupCleanup/IdentifyInactiveGrp.js b/Server-Side Components/Scheduled Job/inactiveGroupCleanup/IdentifyInactiveGrp.js new file mode 100644 index 0000000000..7e9ae98ebc --- /dev/null +++ b/Server-Side Components/Scheduled Job/inactiveGroupCleanup/IdentifyInactiveGrp.js @@ -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 +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'); + 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. + 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.'); +} From 2e3f11a0eb9c855ac0c2e17b7402237c06918d47 Mon Sep 17 00:00:00 2001 From: Abhishek Pandey <91930405+bird-03@users.noreply.github.com> Date: Mon, 6 Oct 2025 00:39:13 +0530 Subject: [PATCH 2/2] Create README.md 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 --- .../Scheduled Job/inactiveGroupCleanup/README.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Server-Side Components/Scheduled Job/inactiveGroupCleanup/README.md diff --git a/Server-Side Components/Scheduled Job/inactiveGroupCleanup/README.md b/Server-Side Components/Scheduled Job/inactiveGroupCleanup/README.md new file mode 100644 index 0000000000..0c906dee06 --- /dev/null +++ b/Server-Side Components/Scheduled Job/inactiveGroupCleanup/README.md @@ -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 + +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