How to prevent use to submit incident when they selected inactive assignment group
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2023 12:08 AM
Hi ,
we have a requirement, if user selected inactive assignment group, we should prevent then to submit the form.
here due to some other reasons we can't write reference qualifier on assignment group field.
I have written below script include and on submit client script but it is not working as expected .
Can any one help me on this?
Client script :
function onSubmit() {
var group = g_form.getValue('assignment_group');
var ga = new GlideAjax('prevent_incident_submission');
ga.addParam('sysparm_name', "getUserInfo");
ga.addParam('sysparm_assignment_group', group); //Onchange field is reference field to sys_user table
ga.getXML(getgroupname);
function getgroupname(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer == 'true') {
g_form.addInfoMessage('please select active group');
g_form.clearValue('assignment_group');
}
}
}
****************
Script include :
var prevent_incident_submission = Class.create();
prevent_incident_submission.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUserInfo: function() {
var agroup = this.getParameter('sysparm_assignment_group');
var group = new GlideRecord("sys_user_group");
group.addQuery('assignment_group', agroup);
group.addQuery('active', false);
group.query();
if (group.next()) {
var response = group.active.getDisplayValue();
}
return response;
},
type: 'prevent_incident_submission'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2023 01:20 AM
what debugging did you do?
did you add alert in client script? did you add log in script include
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2023 02:19 AM
Could please help me how can i debug or add log?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2023 03:32 AM
adding alert in client side and gs.info() in server side
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2023 01:43 AM
Here's an example of a script include and a client script that prevent users from submitting a form if they have selected an inactive assignment group:
---------Script Include---------
var ValidateAssignmentGroup = Class.create();
ValidateAssignmentGroup.prototype = {
initialize: function() {
},
validate: function(current) {
var assignmentGroup = current.assignment_group;
if (assignmentGroup && assignmentGroup.active === false) {
alert("The selected assignment group is inactive. Please select an active assignment group.");
return false;
}
return true;
},
type: 'ValidateAssignmentGroup'
};
-------------Client Script--------
function onSubmit() {
var validateAssignmentGroup = new ValidateAssignmentGroup();
var result = validateAssignmentGroup.validate(g_form.getEditableRecord());
return result;
}
Please mark this helpful and accept my solution if it is helpful.
Regards
Ravi Gaurav
If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!
Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI
ï”— YouTube: https://www.youtube.com/@learnservicenowwithravi
ï”— LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2023 02:33 AM
Hello Ravi,
if user this script i am getting below message in the incident form
onSubmit script error: ReferenceError: ValidateAssignmentGroup is not defined:
function () { [native code] }