How to restrict form submission if user is not a part of a group in catalog item?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2022 08:54 PM
Hi All,
I have a requirement. I have two fields 'Requested for' and 'Product Group'. I need to check if 'Requested for' user is part of the 'Product Group'. If he is a part of the group the form will get submitted or else it will throw an error message and the form won't get submitted.
I have written one client script and script include but its not restricting the users to submit.
Client Script:
function onSubmit() {
//Type appropriate comment here, and begin script below
var userName = g_form.getValue('requested_for');
alert(userName);
var prodGrp = g_form.getValue('product_team');
alert(prodGrp);
var ga = new GlideAjax('RestrictUser');
ga.addParam("sysparm_name", "checkUser");
ga.addParam("sysparm_user_name", userName);
ga.addParam("sysparm_grp_name", prodGrp);
ga.getXML(checkProdTeam);
function checkProdTeam(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
var stop = false;
if (answer == 'false') {
stop = true;
//g_form.setValue('product_team', answer);
g_form.addErrorMessage(getMessage('User not part of Product Team'));
return false;
}
}
}
Script Include:
var RestrictUser = Class.create();
RestrictUser.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkUser: function(){
var uname = this.getParameter('sysparm_user_name');
var pgroup = this.getParameter('sysparm_grp_name');
var a = new GlideRecord('sys_user_grmember');
a.addQuery('user', uname);
a.addQuery('group', pgroup);
a.query();
if(a.next()){
return true;
}
else {
return false;
}
},
type: 'RestrictUser'
});
Please help!
Thanks in advance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2022 09:54 PM
Hi Tadz,
We don't have any role in the Product team hence won't be able to use the first approach. Can you help me with the client script and script include?
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2022 10:00 PM
Your script seems correct.
can you try checking this link if this could help
https://community.servicenow.com/community?id=community_question&sys_id=e47ff36fdb449c10f7fca851ca9619be
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2022 11:32 PM
Hi
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2022 09:49 PM
Hi,
Instead of doing this you can get only the members of Product group in Requested for by adding 1 line code. Let me know if you want to implement this.
Thanks,
Prashant
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2022 09:52 PM
Hi Prashant,
I want to check if the requested for user is part of the product group, then only he will be able to submit the form otherwise not.
Thanks