Skip to content

Hide Section

Overview

You can show or hide an entire form section using a Client Script and g_form.setSectionDisplay(). This is useful in situations like only showing a set of fields when a record is first being submitted (i.e. the record doesn’t exist yet), or toggling between two alternate sections based on a field’s value.

Finding the Section Name

The name setSectionDisplay() expects is auto-generated by the system, not the label shown on the form. To derive it from the label:

  • Lowercase the entire label.
  • Replace the first space with an underscore.
  • Remove all remaining spaces.
  • Remove any other non-alphanumeric characters (e.g. &).

Example: Label "Section Four is Here" → Section name section_fourishere

Example

The following onLoad Client Script toggles between an Asset Lookup section and a Dispose Unlisted Asset section depending on whether the record is new and whether the u_unlisted_asset field is checked:

HideSection.js
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
function onLoad(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

    // If the record is being created show the Asset Lookup section but hide the Dispose Unlisted Asset section
    if (g_form.isNewRecord()) {
        g_form.setSectionDisplay('asset_lookup', true);
        g_form.setSectionDisplay('dispose_unlistedasset', false);
    }
    // If the record has the Unlisted Asset field set to true then hide the Asset Lookup section but show the Dispose Unlisted Asset section
    else if (g_form.getBooleanValue('u_unlisted_asset')) {
        g_form.setSectionDisplay('asset_lookup', false);
        g_form.setSectionDisplay('dispose_unlistedasset', true);
    }
    else {
        // Else set the display of the Asset Lookup section and Dispose Unlisted Asset to be hidden.
        g_form.setSectionDisplay('asset_lookup', false);
        g_form.setSectionDisplay('dispose_unlistedasset', false);
    }
}
setSectionDisplay() only works for onLoad and onChange Client Scripts, and only on sections — it cannot show or hide individual fields (use g_form.setVisible() for that).
Last updated on