- 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-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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2025 06:24 AM
g_form.setVisible(fieldName, true/false)
- Used to show or hide a field completely — label, field, and the space it takes on the form.
- It removes the field from the layout when hidden.
- Think of it like making the field vanish as if it was never there.
Example:
g_form.setVisible('priority', false);
The "Priority" field will disappear completely from the form.
g_form.setDisplay(fieldName, true/false)
- Also shows or hides a field, but it preserves the space where the field would appear.
- So the field is hidden, but an empty gap will still be there in the layout.
- Good for maintaining form alignment when hiding fields.
Example:
g_form.setDisplay('priority', false);
The "Priority" field will be hidden, but the space it takes will still be there, creating a blank spot.
If my answer helped you in any way, please consider marking it as helpful and accepting it as the solution