- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2025 05:25 AM
Hello ServiceNow community!
Can you please explain me the difference between setVisible and setDisplay on g_form?
Regards,
Raju
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2025 05:30 AM - edited ‎06-21-2025 05:31 AM
Hello @dekici3925 !
g_form.setVisible() and g_form.setDisplay() are both used to hide or show fields on a form, but they differ in how they affect the layout.
- g_form.setVisible() not only hides the specified field but also removes its space from the form layout, resulting in a cleaner and more compact appearance. This is useful when you want to dynamically adjust the form without leaving empty gaps.
- g_form.setDisplay() hides the field but retains the space it occupies, which can result in blank areas on the form. This can be intentional if preserving layout structure is important, but generally, setVisible() is preferred when optimizing form appearance.
Please consider marking my answer as helpful and accepting it as the solution if it assisted you in any way.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2025 05:30 AM - edited ‎06-21-2025 05:31 AM
Hello @dekici3925 !
g_form.setVisible() and g_form.setDisplay() are both used to hide or show fields on a form, but they differ in how they affect the layout.
- g_form.setVisible() not only hides the specified field but also removes its space from the form layout, resulting in a cleaner and more compact appearance. This is useful when you want to dynamically adjust the form without leaving empty gaps.
- g_form.setDisplay() hides the field but retains the space it occupies, which can result in blank areas on the form. This can be intentional if preserving layout structure is important, but generally, setVisible() is preferred when optimizing form appearance.
Please consider marking my answer as helpful and accepting it as the solution if it assisted you in any way.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2025 05:32 AM
Clear! Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2025 12:34 AM
Hello,
Thank you for providing the answer. But isn't it the opposite, where g_form.setVisible() keeps the space after hiding and g_form.setDisplay() hides the field and also removes the space.
This is how i used it last time. You can just correct it, so that it will be helpful for anyone checking this answer later.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2025 05:36 AM
Hi @dekici3925
setVisible(): Hides the field, but the space it occupied remains visible on the form, potentially creating a blank space.
setDisplay(): Hides the field and removes the space it occupied, causing other elements to shift and fill the void.
Always it's better to go with setDisplay()
Regards
Chaitanya