- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2024 11:51 PM - edited 12-11-2024 12:21 AM
Hi team,
i have requirement to show only department based assignment groups for assigning to assignment group based on current logged user --> groups department
Please advice
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2024 03:23 AM
This should give you all assignment groups where the department is the logged in user's groups department:
var UserGroupUtils = Class.create();
UserGroupUtils.prototype = {
getUserGroupDepartments: function() {
var userGroupDepartments = [];
var grGroupMember = new GlideRecord('sys_user_grmember');
grGroupMember.addQuery('user', gs.getUserID());
grGroupMember.addQuery('group.active', true);
grGroupMember.query();
while (grGroupMember.next()) {
// Replace u_department with the required field name
var groupDepartment = grGroupMember.group.u_department.toString();
userGroupDepartments.push(groupDepartment);
}
// Replace u_department with the required field name
return 'u_departmentIN' + userGroupDepartments.toString(); // Query containing all assignment groups where u_department is one of the logged in user's groups department
},
type: 'UserGroupUtils '
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2024 12:27 AM
You are asking us for a solution to show groups based on the department of the user and your haven't mapped the users to a department? How are you setting the relationship then? Filtering on data that isn't available won't work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2024 01:06 AM - edited 12-11-2024 01:20 AM
As far as I'm aware there's no department reference on sys_user_group table OOB. Do you have a custom field referencing cmn_department on the group table? If you want to fetch departments mapped on the logged in user's groups, you would need a script include to build the query. The script will look something like this:
var UserGroupUtils = Class.create();
UserGroupUtils .prototype = {
getUserGroupDepartments: function() {
var userGroupDepartments = [];
var grGroupMember = new GlideRecord('sys_user_grmember');
grGroupMember.addQuery('user', gs.getUserID());
grGroupMember.addQuery('group.active', true);
grGroupMember.query();
while (grGroupMember.next()) {
// Replace u_department with the required field name
var groupDepartment = grGroupMember.group.u_department.toString();
userGroupDepartments.push(groupDepartment);
}
return 'sys_idIN' + userGroupDepartments.toString();
},
type: 'UserGroupUtils '
};
You can call this method in the advanced reference qualifier of the department field where you want the filter like this:
javascript: new UserGroupUtils().getUserGroupDepartments();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2024 02:07 AM
yes department is custom field
i almost got solution but here i need to write this on assignment group field which is on task table for sc_task using dictionary override i need all the groups which has same department as logged user groups department
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2024 03:23 AM
This should give you all assignment groups where the department is the logged in user's groups department:
var UserGroupUtils = Class.create();
UserGroupUtils.prototype = {
getUserGroupDepartments: function() {
var userGroupDepartments = [];
var grGroupMember = new GlideRecord('sys_user_grmember');
grGroupMember.addQuery('user', gs.getUserID());
grGroupMember.addQuery('group.active', true);
grGroupMember.query();
while (grGroupMember.next()) {
// Replace u_department with the required field name
var groupDepartment = grGroupMember.group.u_department.toString();
userGroupDepartments.push(groupDepartment);
}
// Replace u_department with the required field name
return 'u_departmentIN' + userGroupDepartments.toString(); // Query containing all assignment groups where u_department is one of the logged in user's groups department
},
type: 'UserGroupUtils '
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2024 07:44 AM
thank you so much
it is working perfectly but last thing i need to include additional filter is type is itil but it is not working as groups showing based on logged user group department fetched