- 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 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2025 12:39 AM
Hello,
g_form.setVisible() keeps the space after hiding the field and g_form.setDisplay() hides the field and also removes the space which was occupied by it.
Hope the answer helps!
Happy Learning!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2025 01:09 AM
Feature setVisible() setDisplay()
Hides Field? âś… Yes âś… Yes
Space taken? ✅ Yes (blank space shown) ❌ No (completely removed)
Use Case When hiding but keeping layout When removing field entirely
If my answer helped you in any way, please consider marking it as helpful and accepting it as the solution