Requirement
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
If a group has child groups, don’t deactivate it (parent group).
If a group has a parent, don’t deactivate it (child group).
Only deactivate standalone groups (no members, no parent, no children).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
you can implement this requirement in by adding a Before business rule or flow on table sys_user_group with logic like: when the Active field is being set to false, check sys_user_grmember to ensure there are no members, check parent is empty (i.e...... no parent group), and check there are no child groups referencing this group in the parent field, only if all these are true allow deactivation; otherwise abort and throw an error.....
If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi @Prithvi Ramesh1 ,
Try below script
var gr = new GlideRecord('sys_user_group');
gr.addActiveQuery(); // Only active groups
gr.query();
var count = 0;
while (gr.next()) {
var groupSysId = gr.getUniqueValue();
var hasMembers = new GlideRecord('sys_user_grmember');
hasMembers.addQuery('group', groupSysId);
hasMembers.setLimit(1);
hasMembers.query();
if (hasMembers.next()) {
continue; // skip, has members
}
// --- Check for parent group ---
if (!gr.parent.nil()) {
continue; // skip, has a parent
}
// --- Check for child groups ---
var hasChildren = new GlideRecord('sys_user_group');
hasChildren.addQuery('parent', groupSysId);
hasChildren.setLimit(1);
hasChildren.query();
if (hasChildren.next()) {
continue; // skip, has children
}
gr.active = false;
gr.update();
count++;
gs.info('Deactivated group: ' + gr.name);
}
gs.info('Total deactivated standalone groups: ' + count);
Regards,
Ranjit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
so what script did you start with and where are you stuck?
You can easily get the script done with any AI tool
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
