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 12:14 AM
Hi Rajeev,
what about filtering out the inactive groups in the first place? (--> what reasons are valid to not change the ref qualifier? As I see no reason why one should be able to select an inactive group)
BR,
Barry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2023 12:44 AM
Hello Barry,
we have a UI action called copy incident on incident, when users are selected that UI action from old incident, al the details will auto populated along with assignment group from old incident to new incident. Hence we need to stop submitting incident with assignment group
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2023 06:02 AM
I'm with Barry. If this is the result of a copy operation, then the copy operation should take care to ensure that all of the data it is copying is valid. That is the best way to handle this. If the support group is inactive then clear out the value of the support group while you are copying the incident.
The opinions expressed here are the opinions of the author, and are not endorsed by ServiceNow or any other employer, company, or entity.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2023 07:13 AM - edited ‎04-27-2023 07:14 AM
If the copying is coming from a UI Action, you can modify the script so it will NOT copy certain field values.
This UI Action script is copying all field values from a Change Request and creating a new Emergency Change Request with all the values from the "source" except for the two I specifically do not want it to copy; number and state.
var gr = new GlideRecord('change_request');
gr.get(current.sys_id);
var oldNumber = gr.number;
var newGr = new GlideRecord('change_request');
for (var field in gr) { //copy all fields except 'number' and 'state'
if (field != 'number' && field != 'state') {
newGr[field] = gr[field];
}
}
_closeItOut(); //* cancel original record
newGr.type = 'emergency';
newGr.u_change_type = 'Emergency';
newGr.insert();
action.setRedirectURL(newGr);
gs.addErrorMessage("Please enter an Emergency Justification reason");
function _closeItOut() {
gs.addInfoMessage("The original Change " +oldNumber+ " has now been canceled");
gr.setWorkflow(false);
gr.state = 4;
gr.u_cancel_reason = 'no longer needed';
gr.active = false;
gr.update();
}