How to get a Mandatory field in a Business Rule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2022 01:07 AM
Hi.
I have Mandatory set for some fields, but I want to change the content of the error message that is displayed.
This time, the UI Policy cannot be used due to complicated requirements.
So I want to use the Business Rule (On Before) to get the Mandatory field, what should I do?
Thank you!
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2022 01:24 AM
Hello Ereshkigal,
In your business rule you simply validate the content of the field and abort the action if the field is empty.
Something like:
(function executeRule(current, previous /*null when async*/ ) {
if (current.field_name == "") {
gs.addErrorMessage("Field abc is empty!");
current.setAbortAction(true);
action.setRedirectURL(current);
}
})(current, previous);
Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!
Best Regards,
Filipe Cruz

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2022 01:45 AM
I am guessing this is a duplicate question. If yes, I have tried to answer your other question - https://community.servicenow.com/community?id=community_question&sys_id=5ca0d0b0db03c150fd8d2b691396...