- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2025 03:25 PM
I am trying to hide the field by using Client Script, but I am not by using the script below. Only setMandatory is working, but setVisible is not working.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2025 05:50 PM
@SaitejaN Try making the field mandatory false first and then set the visible flag.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
if(newValue){
g_form.setVisible('os_version',true);
g_form.setMandatory('os_version',true);
}else {
g_form.setMandatory('os_version',false);
g_form.setVisible('os_version',false);
}
}
Another approach to address this requirement is via a UI Policy. Where you can check the field value on the condition builder and check the reverse if false check box. In the UI Policy actions you can make OS version field visible and mandatory.
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2025 05:56 PM
Hello @SaitejaN
You need to set the mandatory field as false and then the visible field to false.
Here is the updated script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
if(newValue){
g_form.setVisible('os_version',true);
g_form.setMandatory('os_version',true);
}else {
g_form.setMandatory('os_version',false);
g_form.setVisible('os_version',false);
}
}
Refer this servicenow docs for your reference: KB0718566
Hope this helps!
"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"
Thank You
Juhi Poddar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2025 06:26 PM
You cannot hide a mandatory field. To hide it, first make it non-mandatory, and then proceed to hide it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2025 06:45 PM
The behavior you’re experiencing is due to a conflict between the visibility and mandatory state of the field. In ServiceNow, a field cannot be hidden (setDisplay or setVisible) and mandatory (setMandatory) at the same time. When a field is mandatory, the invisible state is effectively ignored because field has to been fulfill.
Regards,
Mimi Edet
LinkedIn: https://www.linkedin.com/in/edet-promise/
=========================================================
If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful."
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2025 06:54 PM
Thank you @Juhi Poddar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2025 06:26 PM
You cannot hide a mandatory field. To hide it, first make it non-mandatory, and then proceed to hide it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2025 07:03 PM
Thank you @Omkar Mone
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2025 06:45 PM
The behavior you’re experiencing is due to a conflict between the visibility and mandatory state of the field. In ServiceNow, a field cannot be hidden (setDisplay or setVisible) and mandatory (setMandatory) at the same time. When a field is mandatory, the invisible state is effectively ignored because field has to been fulfill.
Regards,
Mimi Edet
LinkedIn: https://www.linkedin.com/in/edet-promise/
=========================================================
If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful."
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2025 07:03 PM
Thank you @Mimi Edet