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 11:33 PM
Hi
Thanks!