Logged in user should be a part of a group then only he can submit the form, other users cannot
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2024 07:22 PM - edited 11-17-2024 07:22 PM
Hello Experts,
I am trying to achieve this requirement - User should not be able to submit a catalog request if he is not a part of the software group.
Tried with below On submit Client script and Script Include, but its not giving result, Can u plz help whats wrong here ?
On Submit Client Script :
function onSubmit() {
//Type appropriate comment here, and begin script below
var part = g_form.getValue('name_of_the_partition');
var reqTyp = g_form.getValue('request_type');
if ((part == 'major || 'minor') && reqTyp == "software") {
var ga = new GlideAjax('UserUtils');
ga.addParam('sysparm_name', 'checkGroupUser');
ga.getXML(checkGroupUser);
}
function checkGroupUser(response) {
var result = response.responseXML.documentElement.getAttribute("answer");
if (result == 'true') {
return true;
} else {
g_form.addErrorMessage("User not eligible to submit the form");
return false;
}
}
}
var UserUtils = Class.create();
UserUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkGroupUser: function() {
return gs.getUser().isMemberOf('TMG Catalog Users');
},
type: 'UserUtils'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2024 07:48 PM
Hi @Mishu Try below code
function onSubmit() {
var part = g_form.getValue('name_of_the_partition');
var reqTyp = g_form.getValue('request_type');
if ((part == 'major' || part == 'minor') && reqTyp == "software") {
var ga = new GlideAjax('UserUtils');
ga.addParam('sysparm_name', 'checkGroupUser');
ga.getXMLAnswer(function(response) {
if (response == 'true') {
return true;
} else {
g_form.addErrorMessage("User not eligible to submit the form");
return false;
}
});
return false;
}
return true;
}
var UserUtils = Class.create();
UserUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkGroupUser: function() {
return gs.getUser().isMemberOf('TMG Catalog Users') ? 'true' : 'false';
},
type: 'UserUtils'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2024 07:59 PM - edited 11-17-2024 08:00 PM
Its not working in the case where user is part of the group, it should allow him to submit.
For users who are not part of the group, its working fine
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2024 08:45 PM
Hi @Mishu
Instead of complicating this requirement with a Script Include, you can create a user criteria for the catalog item. Refer https://www.servicenow.com/community/developer-forum/catalog-form-should-be-submitted-only-by-a-part...
Thanks and Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2024 09:16 PM
Yes but I have condition along with that, when request type is software and part is minor or major then only user out of group should not be able to submit it