Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to identify mandatory fields in Client Script

harinalamalapu
Giga Expert

I want to identify the mandatory fields (something like g_form.isMandatoryFieldEmpty) in a Client Script to add a field message (error message) for all such fields when left blank on the form. Can you think of a way to iterate through the fields on the form and check if they are mandatory but empty?

Note: I can hard code the required fields in the script to add field message. But I am trying to identify an alternative way where I should identify only the mandatory fields to add field message so that script need not be updated again in future when a new field is made mandatory.

1 ACCEPTED SOLUTION
5 REPLIES 5

Michael Fry1
Kilo Patron

You might be better served by using a UI Policy. If any mandatory fields are left blank, the system will pop-up a message letting the user know which fields need to be populated.


harinalamalapu
Giga Expert

Hello Michael, Thank you for taking a look at my question. Even though we are able to implement it using UI Policy, I have a special requirement to display a custom error message underneath the mandatory field when left blank so I am taking this approach.


Check out this article: Mandatory Check


This helped me today. Thanks for sharing.