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

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.

Clear! Thanks.

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. 

Chaitanya ILCR
Kilo Patron

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