Requirement is to hide assignment groups from drop down if requestor is a member of the group
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2024 01:49 AM
Requirement is to hide assignment groups from drop down if requestor is a member of the group in catalog item.
Example i have a ABC variable which is referenced to sys_user_group table and will have active groups in drop down.
I have a variable XYZ where we need to give user name who need access, so when person name is given on ABC drop down only group which he is not member should be visible.
ABC is a variable in multirow and XYZ is single row variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2024 02:37 AM - edited 04-10-2024 02:37 AM
Here is the query to get the list of groups you are not part of.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2024 08:58 AM
Can u pls tell whether i need to include this script in script include and call that in my reference qual
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2024 02:51 AM
Client script:
var requestor = g_form.getValue('XYZ'); // Get the value of the requestor field
var ajax = new GlideAjax('MyScriptInclude'); // Create a GlideAjax object
ajax.addParam('sysparm_name', 'getUserMembership'); // Set the server-side function to call
ajax.addParam('requestor', requestor); // Pass the requestor's username
ajax.getXMLAnswer(function(response) {
var groups = response.split(','); // Parse the response to get the list of groups
var assignmentGroupOptions = g_form.getOptions('ABC'); // Get the assignment group options
for (var i = 0; i < assignmentGroupOptions.length; i++) {
var groupName = assignmentGroupOptions[i].value;
if (groups.indexOf(groupName) !== -1) {
// Hide the assignment group option if the requestor is a member
g_form.removeOption('ABC', groupName);
}
}
}
Script inlclude:
getUserMembership: function(requestor) {
var membership = '';
// Query the sys_user_grmember table to fetch groups the user is a member of
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', 'CONTAINS', requestor); // Filter by the requestor's username
gr.query();
// Iterate through the results and concatenate group names
while (gr.next()) {
var groupName = gr.group.getDisplayValue(); // Get the display value of the group
membership += groupName + ',';
}
// Remove the trailing comma
membership = membership.slice(0, -1);
return membership;
},
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2024 10:03 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2024 06:56 PM