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

Ankur Bawiskar
Tera Patron
Tera Patron

@rajeevsnow 

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.

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

Hello Anukur,

But how can we stop submitting and it should give error message and clear assignment group value one we try to save

@rajeevsnow 

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.

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

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

@rajeevsnow 

then you can use before insert/update BR and validate the same.

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