Hide fields in user table using client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2024 07:27 AM
In my user table, I have created a section called 'Additional details', In that section I have 5 fields in it, I need to hide 2 of those 5 fields using client script. Can anyone help me on this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2024 07:59 AM
Hi @Govind Bysani ,
To conditionally hide fields in a form, choose the appropriate client script type (e.g., onload, onchange) and use the g_form.setDisplay('field_name', false) method within the script. This allows you to customize field visibility based on your specific requirements.
Please let me know if this helps! You can mark this answer as "Correct" if it resolves your issue, and "Helpful" if you find it valuable.
Thanks,
Astik Thombare

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2024 08:07 AM
setDisplay(String fieldName, Boolean display)
This method cannot hide a mandatory field with no value. If the field is hidden, the space is used to display other items. Whenever possible, use a UI policy instead of this method.
Here is an example
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
//If the page isn't loading
if (!isLoading) {
//If the new value isn't blank
if (newValue != '') {
g_form.setDisplay('priority', false);
}
else
g_form.setDisplay('priority', true);
}
}
Here is the API reference https://developer.servicenow.com/dev.do#!/reference/api/vancouver/client/c_GlideFormAPI#r_GlideFormS...
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2024 08:12 AM
Hi @Govind Bysani ,
You can create one onload , onchange client scripts on this user table like shown in below.
table : sys_user
condition based you want hide and show?
for example I am providing the condition as while onchange on checkbox, script. You can hide the fields according to the checkbox value is true/false those fields can be shown,
script:
If it is helpful please make it correct/helpful.
Thanks and Regards,
Allu Gopal.