Skip to content
Merged
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,10 @@
There are instances where groups are created but remain without members for an extended period, making them ineffective.
This script helps identify such groups that have no members within a specified timeframe and make them inactive.

Scenario-
Deactivate the active groups which doesn't have members for last 6 months.
Approach-
1. A scheduled job runs daily or weekly to identify groups without members.
2. To track when a group becomes memberless, a Date field (e.g. u_memberless_date) is added to the sys_user_group table and populated with the current date when no members are found.
3. If members are added later, the field value is cleared.
4. Groups that remain memberless for over six months (based on the u_memberless_date) are automatically deactivated.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
var groupGr = new GlideRecord('sys_user_group');
groupGr.addActiveQuery();
groupGr.query();
while (groupGr.next()) {
var groupSysId = groupGr.sys_id.toString();
// Query Group member table
var memberGr = new GlideRecord('sys_user_grmember');
memberGr.addQuery('group', groupSysId);
memberGr.query();
if (memberGr.hasNext()) {
// If group has member but date is also populated that means member has joined recently. Clear the field value.
if (!gs.nil(groupGr.u_memberless_date)) {
groupGr.u_memberless_date = '';
groupGr.update();
}
} else {
var today = new GlideDate();
if (gs.nil(groupGr.u_memberless_date)) {
// If group doesn't have member populate the fields with today's date if doesn't have a value.
groupGr.u_memberless_date = today;
groupGr.update();
} else {
// If the field value is present compare the dates and deactivate group accordingly.
var fieldDate = groupGr.getValue('u_memberless_date');
today.addMonths(-6);
if (fieldDate < today) {
groupGr.active = false;
groupGr.description = "Group has been deactivated for not having members in last 6 months.";
groupGr.update();
}
}
}
}
Loading