Retrieving and Managing Form Section Names in ServiceNow
- kelly.ryu
- Mar 19
- 2 min read
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.