Skip to content

Commit d2e95cc

Browse files
Feature/memberless group inactive (#2101)
* Create README.md Information on working of the script. * Create Deactivate memberless group * Rename Server-Side Components/Scheduled Jobs/README.md to Server-Side Components/Scheduled Jobs/Deactivate Memberless Group/README.md Utility script to deactivate memberless group * Delete Server-Side Components/Scheduled Jobs/Deactivate memberless group Delete obsolete file * Update README.md Updating readme file * Create deactivate group.js adding scripts with comments
1 parent 312f2f0 commit d2e95cc

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
There are instances where groups are created but remain without members for an extended period, making them ineffective.
2+
This script helps identify such groups that have no members within a specified timeframe and make them inactive.
3+
4+
Scenario-
5+
Deactivate the active groups which doesn't have members for last 6 months.
6+
Approach-
7+
1. A scheduled job runs daily or weekly to identify groups without members.
8+
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.
9+
3. If members are added later, the field value is cleared.
10+
4. Groups that remain memberless for over six months (based on the u_memberless_date) are automatically deactivated.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
var groupGr = new GlideRecord('sys_user_group');
2+
groupGr.addActiveQuery();
3+
groupGr.query();
4+
while (groupGr.next()) {
5+
var groupSysId = groupGr.sys_id.toString();
6+
// Query Group member table
7+
var memberGr = new GlideRecord('sys_user_grmember');
8+
memberGr.addQuery('group', groupSysId);
9+
memberGr.query();
10+
if (memberGr.hasNext()) {
11+
// If group has member but date is also populated that means member has joined recently. Clear the field value.
12+
if (!gs.nil(groupGr.u_memberless_date)) {
13+
groupGr.u_memberless_date = '';
14+
groupGr.update();
15+
}
16+
} else {
17+
var today = new GlideDate();
18+
if (gs.nil(groupGr.u_memberless_date)) {
19+
// If group doesn't have member populate the fields with today's date if doesn't have a value.
20+
groupGr.u_memberless_date = today;
21+
groupGr.update();
22+
} else {
23+
// If the field value is present compare the dates and deactivate group accordingly.
24+
var fieldDate = groupGr.getValue('u_memberless_date');
25+
today.addMonths(-6);
26+
if (fieldDate < today) {
27+
groupGr.active = false;
28+
groupGr.description = "Group has been deactivated for not having members in last 6 months.";
29+
groupGr.update();
30+
}
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)