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 OnSubmit Client script - Scoped Table

Supriya25
Tera Guru

Hi All,

I am selecting mandatory field but still it is showing false.

g_form.isMandatory("x_ifvg_gh_how_taken");  //Scoped Table field //

what is the best way to to identify Mandatory fields. why g_form.isMandatory not working in ServiceNow Scoped Table ?
2 REPLIES 2

Jennifer Metz
Mega Guru

Hello @Supriya25,

 

I am happy to help.

 

Have you checked the form to confirm the field is actually displaying as mandatory (red asterisk) and that it is enforced on submit? Also, can you share how the field is being made mandatory... dictionary, UI Policy, Data Policy, or client script?

 

One common reason g_form.isMandatory() can be confusing is that mandatory can be applied in more than one place, and when multiple mechanisms are used the results can be unpredictable.

 

I’ve also seen cases where metadata/caching causes odd behavior. In those situations, toggling the mandatory flag off/on and clearing cache or reloading the form can help. As a quick test, you can also try enforcing mandatory using one method like UI Policy or g_form.setMandatory() to see if the behavior changes.

 

I hope this helps!

 

 

Jennifer Metz
Sr. ServiceNow Developer | Infosys

kaushal_snow
Giga Sage

@Supriya25 ,

 

Because the form API in scoped app and certain views doesn’t always reflect ui policy or dictionary mandatory setting the same way it does in global ui.....so instead of relying on isMandatory() you should use methods like checking for missing required fields via g_form.getMissingFields() or evaluate ui policy/dictionary attributes directly before submit, and in some cases.........you can build logic that loops through field names and checks if they are mandatory and have no value rather than depending on isMandatory() alone, because in scoped or workspace contexts some of the g_form validation methods behave differently or aren’t available as expected and ui Policy is the recommended approach for enforcing mandatory behavior rather than just reading it in an onSubmit client script.........

 

If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.

 

Thanks and Regards,
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/