Assignment group variable shoud display only groups which the user belongs to ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2024 01:02 PM
Hi team,
I have catalog form having Group variable (which contains few groups called Group1,Group2,Group3,Group4,Group5,Group6) if the Requsted user is member of only these 3 groups like (Group1,Group2 and Group3) then it should display only 3 groups called (Group1,Group2 and Group3) in Group variable How can I achieve this ?
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2024 01:28 PM
Hi @raj99918 ,
You can achieve this by a onLoad ckient script.
Please create a catalog cliend script of type onLoad-
function onLoad() {
var assignmentGroupField = 'assignment_group';
// GlideAjax call to get the user's groups
var ga = new GlideAjax('AssignmentGroupAjax');
ga.addParam('sysparm_name', 'getUserGroups');
ga.getXMLAnswer(function(response) {
var groupSysIds = response.split(',');
var filter = 'sys_idIN' + groupSysIds.join(',');
// Set the filter on the assignment group field
g_form.setReferenceFilter(assignmentGroupField, filter);
});
}
Script include-
var AssignmentGroupAjax = Class.create();
AssignmentGroupAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUserGroups: function() {
var userGroups = [];
var userId = gs.getUserID();
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', userId);
gr.query();
while (gr.next()) {
userGroups.push(gr.group.sys_id.toString());
}
return userGroups.join(',');
}
});
If my response has resolved your query, please consider giving it a thumbs up and marking it as the correct answer!
Thanks & Regards,
Sanjay Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2024 01:45 PM
Hi @Community Alums Thanks for the script but here How can I exclude the groups which was user is not part ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2024 04:16 PM
Hi @raj99918,
You need to update the filter in client script.
Below is the updated script-
Client Script (onLoad)
function onLoad() {
// The name of the variable that you want to filter
var assignmentGroupField = 'assignment_group';
// GlideAjax call to get the user's groups
var ga = new GlideAjax('AssignmentGroupAjax');
ga.addParam('sysparm_name', 'getUserGroups');
ga.getXMLAnswer(function(response) {
var groupSysIds = response.split(',');
var filter = 'sys_idIN' + groupSysIds.join(',');
// Set the filter on the assignment group field
g_form.setReferenceFilter(assignmentGroupField, filter);
});
}
Script Include-
var AssignmentGroupAjax = Class.create();
AssignmentGroupAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUserGroups: function() {
var userGroups = [];
var userId = gs.getUserID();
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', userId);
gr.query();
while (gr.next()) {
userGroups.push(gr.group.sys_id.toString());
}
return userGroups.join(',');
}
});
If above solution solves your issue please give it a thumbs up and accept the solution.
Thanks and Regards,
Sanjay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2024 01:41 AM
Hi @Community Alums I didn't find any changes in the updated script could you please let me know where exactly put the filter to exclude the static groups ?