How to prevent use to submit incident when they selected inactive assignment group

rajeevsnow
Tera Contributor

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'
});

 

27 REPLIES 27

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?

@rajeevsnow 

I would suggest to use onChange client script and you need not use onSubmit + GlideAjax

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@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

@rajeevsnow 

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.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

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