How to set a Incident field mandatory using ui action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-17-2023 04:11 AM
How to set a Incident field mandatory using ui action What's the script for this

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-17-2023 04:15 AM
Hi @Bruce lee ,
Why do you want to use a UI action to make any field manadatory?
As per the best practice we should be using UI Policy whihc doesn't involve any scripting.
learn more from the link : UI policies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-17-2023 04:17 AM
your UI action should be client side to make field mandatory
sample script
if(g_form.getValue('fieldName') == ''){
g_form.setMandatory('fieldName', true);
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-25-2025 02:46 AM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-25-2025 02:51 AM
Hello @Bruce lee ,
You can try the below type of script script
// Get the value of the field
var fieldValue = current.field_name;
// Check if the field value is blank
if (!fieldValue) {
// Add an error message to the form
gs.addErrorMessage('Please fill in the field name before submitting the form.');
// Make the field mandatory
g_form.setMandatory('field_name', true);
// Stop the form from being submitted
action.setRedirectURL(current);
}
Just amend the conditions depending upon your requirement and field names.
Please mark it as helpful/correct if this helps you.
Regards,
Debasis