- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 09:30 AM
Hi All,
I have a catalog form and a select box with 3 choices in it. Example: A,B,C.
Only 3 particular group members should be able access 'A' choice. If any user try to select from the drop down it should clear that value with an alert or that choice itself should not be visible to any other user apart from those 3 groups.
And we do not have any variable as assignment group on form. It should check the requester/user's group.
Please assist.
Thanks & Regards.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 10:07 AM - edited 11-20-2023 10:09 AM
It's a much better user experience to remove the choice rather than allow it to be selected, but then present an error in some cases. You can do this with an onLoad Catalog Client Script which uses GlideAjax to call a Script Include
function onLoad() {
var ga= new GlideAjax("CatalogUtils"); //Script Include name
ga.addParam("sysparm_name", "getGroupMembership"); //name of function
ga.addParam("sysparm_user", g_user.userID);
ga.getXML(processResponse);
function processResponse(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer == 'false'){ //current user is not a member of one of the 3 groups
g_form.removeOption("var_name","choice_value"); //replace with your variable name and choice value to be removed
}
}
}
Your Client callable Script Include would look something like this:
var CatalogUtils = Class.create();
CatalogUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getGroupMembership: function(){
var answer = 'false';
var usr = this.getParameter("sysparm_user");
if (gs.getUser(usr).isMemberOf('group name 1')) { //replace with your group name
answer = 'true';
} else if (gs.getUser(usr).isMemberOf('group name 2')) { //replace with your group name
answer = 'true';
} else if (gs.getUser(usr).isMemberOf('group name 3')) { //replace with your group name
answer = 'true';
}
return answer;
},
type: 'CatalogUtils'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2023 07:26 AM
Hi @Brad Bowman ,
After adding this the access_role is getting cleared even for those two group members.
Do we need to update anything here? Please suggest.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2023 11:21 AM
I've lost track - how many client scripts do you have running now, and are they onLoad or onChange? If onChange, which variable triggers the script? What are the steps of your test case - requested for defaults to the current user, who is not a member of one of the three groups, but then you change it to another user that is in one or more of the groups, or what?