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.

Save form and bypass required fields

Andre8
Giga Guru

Hello,

I would like to bypass a required field when the "approve" UI Action is clicked. If I save the form and then select approve, some fields are required for approval. If I attempt to save the form after selecting approve, the field becomes required to save the form. Is there a way to bypass the required field at this point?

Andre8_0-1682952016420.png

This is after clicking approve...If I attempt to save at this point, this field is required. I would like to bypass the required field to save the form

Andre8_1-1682952133806.png

 

 

3 REPLIES 3

Sandeep Rajput
Tera Patron
Tera Patron

@Andre8 You can bypass the mandatory fields using Javascript Executor this is a javascript console exclusively available for users with admin role, they can run the javascript on the fly on a form and can make fields on the form non-mandatory.

 

Here is how I made Caller field non mandatory on incident form.

1. Login as an admin, navigate to the form where you would like to make a field non mandatory press "Alt+Ctrl+Shift+J" on windows or "CTRL+Option+Shift+J" on Mac.

2. Javascript executor will appear like following.

Screenshot 2023-05-01 at 9.21.18 PM.png

2. Add a script to make field non mandatory 

g_form.setMandatory('caller_id',false);

Click on Run my code button to execute this javascript.

 

3. Once this script runs, the field will become non-mandatory and you will be able to save the form.

 

Hope this helps.

"On the fly" will not work in this situation

Bert_c1
Kilo Patron

Hi Andre8,

 

You script is not complete, where are 'wgh' and 'st' initialized? Having the complete context will help us here provide assistance.