What It Does
The setSectionDisplay() method manipulates the CSS display properties of form sections to show or hide entire groups of fields. ServiceNow wraps each form section in a container element, and this method toggles the visibility of that container along with all its child elements.
Internally, ServiceNow maintains a mapping between section display labels and their programmatic identifiers. The method performs a lookup using the provided sectionName parameter to locate the corresponding DOM element. The section name transformation follows a consistent pattern: spaces become underscores, special characters are removed, and the result is converted to lowercase.
The method returns true when it successfully locates and modifies the section's visibility state. It returns false when the section name doesn't match any existing sections on the form. This return value provides immediate feedback about whether the operation succeeded, unlike many other GlideForm methods that fail silently.
Hiding a section overrides individual field visibility settings within that section. Fields that are normally visible will become hidden when their parent section is hidden, regardless of their individual display state. Conversely, showing a section doesn't automatically make all fields within it visible—individual field visibility rules still apply.
This method works alongside related GlideForm methods like setDisplay() for individual fields and setTabDisplay() for entire tabs. The hierarchy flows from tab to section to field, with each level capable of overriding visibility at lower levels.
When to Use This
Use setSectionDisplay() when you need to control the visibility of multiple related fields as a logical group. This is ideal for conditional sections that should appear or disappear based on other field values, user roles, or business logic. The section-level approach is more maintainable than individually managing multiple field visibility states.
For single field visibility, use setDisplay() instead. For entire tab visibility, use setTabDisplay(). Avoid mixing section and individual field visibility changes for fields within the same section, as this creates unpredictable behavior and maintenance headaches.
Common misuse includes hardcoding section names without accounting for form customizations or internationalization. Section names can change when administrators modify form layouts, breaking scripts that rely on specific naming patterns.
Return Value
Returns a boolean value indicating operation success. true means the section was found and its visibility was modified as requested. false indicates the section name didn't match any sections on the current form.
Always check the return value when section visibility is critical to your business logic. A false return often indicates typos in section names or form configuration changes that have invalidated your script assumptions. Use the return value for error handling and logging.
Enjoying this? Get one deep-dive per week.
Join 1,000+ ServiceNow pros — scripts, GlideRecord patterns, Flow Designer techniques, and career moves. Free.
Platform Behavior & Side Effects
- No server-side events fire—this is purely a client-side DOM manipulation with no database impact
- Changes are not persisted across page refreshes—visibility resets to form configuration defaults
- Performance is fast since it only modifies CSS properties without server round-trips
- Hidden sections don't prevent field validation—mandatory fields in hidden sections can still block form submission
- UI Policies that control the same section can conflict with script-based visibility changes
- Mobile interface behavior may differ from desktop—test section visibility on all target platforms
- Screen reader accessibility may be impacted when sections are dynamically hidden—consider announcing changes