top of page

Experiencing challenges with ServiceNow support?

IKC provides professional, reliable assistance that covers gaps not supported by ServiceNow

and without the high costs of traditional services.

 

Starting from just $1,000

Retrieving and Managing Form Section Names in ServiceNow

Updated: Mar 30

In ServiceNow, form sections help structure and organize related fields effectively, making forms intuitive and user-friendly. For ServiceNow developers, accurately retrieving and managing these form sections programmatically can significantly improve the user experience through dynamic visibility controls and customized interfaces. Understanding how to properly reference form section names is essential for effective client-side scripting and overall form customization.


Understanding Form Section Names


Form section names in ServiceNow follow a standardized format. They are always lowercase, with the first space replaced by an underscore and subsequent spaces removed entirely. Special characters and punctuation marks like ampersands (&) are also eliminated. For example:


  • "User Details" becomes user_details

  • "Approval & Review Section" becomes approvalsection


Understanding this naming convention is crucial for accurately scripting UI behaviors.


How to Retrieve Section Names


ServiceNow provides a straightforward method to retrieve all form section names through the GlideForm API:


var sections = g_form.getSectionNames();
console.log(sections);

This JavaScript snippet outputs an array of all section names associated with the current form, making it easy to identify the correct section name to use in further scripting.


Showing and Hiding Form Sections


Once the correct section name is known, sections can be dynamically shown or hidden using the GlideForm API method setSectionDisplay():

function onLoad() {
  if (g_form.getValue('incident_state') === 'Closed') {
    g_form.setSectionDisplay('closure_information', true);
  } else {
    g_form.setSectionDisplay('closure_information', false);
  }
}

This example illustrates dynamically displaying the "Closure Information" section only when the incident status changes to "Resolved."


Troubleshooting and Alternative Solutions


Common issues often involve incorrect section naming or attempts to hide sections with mandatory fields. Verify exact names with g_form.getSectionNames() to avoid such errors. If encountering issues with the standard method, an alternative is to use g_form.getSections() to directly manipulate DOM elements, although this approach is generally less recommended due to potential instability if forms change.


Effectively managing form sections in ServiceNow involves accurately retrieving section names and dynamically showing or hiding them to enhance user experience. Always follow best practices by verifying section names and avoiding unnecessary DOM manipulation for optimal script performance and maintainability.

Experiencing challenges with ServiceNow support?

IKC provides professional, reliable assistance that covers gaps not supported by ServiceNow

and without the high costs of traditional services.

 

Starting from just $1,000

CONTACT

New Zealand HQ

Integrated Knowledge Consulting Office

Level 3, 93 Grafton Road

Auckland

South Korea

Integrated Knowledge Consulting Office

BMY역삼타워 6층

서울특별시 강남구 역삼동 678-10번지

 

info@ikconsulting.com

Thanks for submitting!

  • LinkedIn Social Icon

© Copyright 2025 Integrated Knowledge Consulting. All rights reserved.

bottom of page