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 10:06 PM - edited ‎04-26-2023 10:22 PM
Yes ,Anukur
i have used that only but when i set abort action(true) i am getting OOTB alert ' invalid input error message' along with custom info message.
Is there any way that we can remove 'invalid input' message ?
Also could please me how can i restrict this business rule to not to run in ServicePortal?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2023 10:27 PM
I would suggest to use onChange client script and you need not use onSubmit + GlideAjax
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 10:32 PM
@Ankur : But here we don't change anything , all the fields auto populate from old incident once we click on copy incident UI action.
I tried Onsubmit and GlideAjax but no luck
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2023 11:05 PM
you need to use synchronous GlideAjax so that the form waits till script include function returns the value
update as this
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.getXMLWait(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');
return false;
}
}
}
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.addActiveQuery();
group.addQuery('sys_id', agroup);
group.query();
return group.hasNext();
},
type: 'prevent_incident_submission'
});
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-27-2023 12:47 AM
Hello Ankur,
Thank you but it is not working for me, when i select inactive or active, nothing is happening
Kindly let me know if there is any other way