Difference between setVisible and setDisplay

dekici3925
Tera Contributor

Hello ServiceNow community!
Can you please explain me the difference between setVisible and setDisplay on g_form?

Regards,
Raju

1 ACCEPTED SOLUTION

iekosmadakis
Mega Sage

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.

View solution in original post

7 REPLIES 7

Pankaj Hatwar
Giga Guru

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

SanjanaK
Tera Expert

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!

sandeep1708
Tera Contributor

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