Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2025 09:11 AM
- User Selection: The form allows selection of multiple users.
- Group Filtering: Based on the selected users, the Group field should dynamically filter and show only the groups that are common to all selected users.
- Validation Logic: This ensures that users are not removed from groups they are not part of, avoiding errors.
Script Include:
var getCommonGroups = Class.create();
getCommonGroups.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCommonGroups: function(userList) {
gs.info("PRITHVI: Starting getCommonGroups with userList = " + userList);
var users = userList.split(',');
var groupCount = {};
var commonGroups = [];
for (var i = 0; i < users.length; i++) {
gs.info("PRITHVI: Checking groups for user = " + users[i]);
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', users[i]);
gr.query();
while (gr.next()) {
var groupId = gr.group.toString();
gs.info("PRITHVI: Found group = " + groupId + " for user = " + users[i]);
groupCount[groupId] = (groupCount[groupId] || 0) + 1;
}
}
for (groupId in groupCount) {
gs.info("PRITHVI: Group " + groupId + " has count = " + groupCount[groupId]);
if (groupCount[groupId] == users.length) {
commonGroups.push(groupId);
gs.info("PRITHVI: Group " + groupId + " is common to all users");
}
}
var result = commonGroups.join(',');
gs.info("PRITHVI: Returning common groups = " + result);
return result;
},
type: 'getCommonGroups'
});
Reference Qualifier:
javascript: 'sys_idIN' + getCommonGroups(current.variables.requestor);
Issue: Wfter selecting the user even though is part of the group the list does not show any groups and even the logs is empty.
Solved! Go to Solution.