-
Notifications
You must be signed in to change notification settings - Fork 908
Schedulejob inactivegroup cleanup #1831
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
| 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'); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
There was a problem hiding this comment.
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.