logo

NJP

Show/Hide Form Sections with Multiple Spaces In the Name

Import · Apr 28, 2020 · article

Problem: Show/Hide Form Sections with client scripts is used quite often and is a very simple , unless you have a long section name with multiple spaces.

Solution: This blog will cover how to tackle all scenarios to hide/show form sections with client side code.

No Spaces in the section name:

For Eg, you have a section called 'Planning'.

To Hide: g_form.setSectionDisplay('planning', false);

To Show: g_form.setSectionDisplay('planning', true);

One Space in the section name: Just replace the space with _

For Eg, you have a section called 'Related Records'.

To Hide: g_form.setSectionDisplay('related_records', false);

To Show: g_form.setSectionDisplay('related_records', true);

Multiple Space in the section name: Replace first space with _ and remove all other spaces

For Eg, you have a section called 'Process And Compliance Details'.

To Hide: g_form.setSectionDisplay('process_andcompliancedetails', false);

To Show: g_form.setSectionDisplay('process_andcompliancedetails', true);

I have spend a few hours in the past struggling with this, and recently saw some else struggle as well so decided to write about this.

Hope it helps.

View original source

https://www.servicenow.com/community/developer-blog/show-hide-form-sections-with-multiple-spaces-in-the-name/ba-p/2286619