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

Try this-----------------

var AssignmentGroupUtils = Class.create();
AssignmentGroupUtils.prototype = {
initialize: function() {
},

isActiveAssignmentGroup: function(assignmentGroupId) {
var gr = new GlideRecord('sys_user_group');
if (gr.get(assignmentGroupId)) {
return gr.active;
}
return false;
},

type: 'AssignmentGroupUtils'
};

In your onsubmit client script, add a reference to your AssignmentGroupUtils script include and use the isActiveAssignmentGroup function to check whether the selected assignment group is active. Here's an example implementation:

 

function onSubmit() {
var assignmentGroupId = g_form.getValue('assignment_group');
var assignmentGroupUtils = new AssignmentGroupUtils();

if (!assignmentGroupUtils.isActiveAssignmentGroup(assignmentGroupId)) {
alert('Please select an active assignment group.');
return false;
}

return true;
}

--------------------------------------------------------------------------------------------------------------------------


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/

mary_lindell
ServiceNow Employee
ServiceNow Employee

Hello Rajeev,

 

A better way may be to stop the user from being presented an inactive assignment group for selection. Place a reference qualifier on the assignment group including the filter "active = true". Here is an example of a reference qualifier on the Task table. This is accomplished as a dictionary entry on the database column.

 

mary_lindell_0-1682602968725.png

 

If you are adding a reference qualifier to the assignment group for an extended table, you can create a dictionary override just for that table. Here is an example of a dictionary override for the assignment group on the sn_hr_core_task table that includes the active = true filter.

 

mary_lindell_1-1682603331901.png

 

This stops the user from ever selecting an inactive assignment group.

If this helped you, please mark this as Helpful.

 

Best wishes,

Mary

Abhit
Tera Guru

@rajeevsnow  - 

You can try this on before update BR to achieve this, and if you want to achieve this with client script then use global variable to toggle your onsubmit client script trigger.

 

Ref: https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0783579

 

Cheers!!

Abhit Singh

 

Please Mark it helpful!! If this helps you to understand.