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-26-2023 01:38 AM
why not use onChange client script on Group field and check if it's inactive
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
var ref = g_form.getReference('assignment_group', callBackMethod);
}
function callBackMethod(ref){
if(ref.active.toString() == 'false'){
g_form.addInfoMessage('please select active group');
g_form.clearValue('assignment_group');
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
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 02:06 AM
Hello Anukur,
But how can we stop submitting and it should give error message and clear assignment group value one we try to save
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2023 02:28 AM
show an error box near that field and user cannot submit the form
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
var ref = g_form.getReference('assignment_group', callBackMethod);
}
function callBackMethod(ref){
if(ref.active.toString() == 'false'){
g_form.showErrorBox('assignment_group', 'please select active group');
g_form.clearValue('assignment_group');
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
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 02:39 AM
Thank you,
But requirement is when user try to submit the form and on changing field.
In this case user not changing group and group is auto populated based on copy incident UI action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2023 07:38 AM
then you can use before insert/update BR and validate the same.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader