How to set a field mandatory through UI Action??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2022 10:36 AM
Hi All,
When we select " Cancel Incident " ui action button on Incident table, The below field should become mandatory :
" resolution Notes " should be mandatory.
here is the current script for "Cancel Incident" button script... I tried updating the below script but its not working. Can any one help me on this :
UI Action Script :
var outage = new GlideRecord('cmdb_ci_outage');
outage.addQuery('task_number', current.sys_id);
outage.addEncodedQuery('beginISNOTEMPTY^ORendISNOTEMPTY');
outage.query();
if (outage.hasNext()) {
gs.addErrorMessage('This incident cannot be canceled because it has at least one related CI outage with a Begin or End date/time. All CI outages Begin and End date/times must be cleared before this incident can be canceled.');
current.setAbortAction(true);
action.setRedirectURL(current);
} else serverResolve();
function serverResolve() {
current.state = 6;
current.close_code = 'Cancelled';
current.u_cause = 'cancelled';
current.u_major_incident = 'false';
current.u_rca_required = 'false';
current.close_notes = 'Cancelled by Caller'; // We need to update this field, since Business Rule is now running "after update"
current.update();
}
Business rule :
if (current.close_notes.nil() && current.state.changesTo(6)) {
if (current.close_code.changesTo('Cancelled')) {
current.close_notes.setValue('Cancelled by Caller');
current.close_notes.setValue('');
} else {
current.close_notes.setValue('Resolved by Caller');
current.close_notes.setValue('');
}
}
if (current.close_code.nil())
current.close_code = "Closed/Resolved by Caller";
if (current.close_notes.nil())
current.close_notes = "Closed by Caller";
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2022 10:53 AM
Have you considered just using a Data Policy for this bit? This way, no matter how the user tries to cancel, the policy will kick in and prevent submission without that field mandatory. The Data Policy would be set to State "changes to" Cancelled, and set Resolution Notes to mandatory (as the Data Policy Action).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2022 10:06 AM
Hi Ryan,
Thanks for your reply,
I tried using data policy...it is setting resolution notes to mandatory but the incident state changing to resolved state automatically and all the fields are greyed out..
that should not happen. When we click on Cancel button on incident, form should stop and display message that resolution notes is mandatory to fill

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2022 10:26 AM
Hello,
Go through below link and implement accordingly
https://servicenowguru.com/system-ui/ui-actions-system-ui/client-server-code-ui-action/
Mark my answer as correct if that helps
Regards
Regards,
Musab