hide a section on change request form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
g_form.setSectionDisplay("A", newValue == 'A');
g_form.setSectionDisplay("a", newValue == 'A')
}Hi @sharley ,
Try this
Is the name of the section is correct ? Or backend name of the value "A" correct?
To know the section name
Follow this
The backend name for a ServiceNow form section is its label converted to lowercase, with the first space becoming an underscore and subsequent spaces/special characters removed (e.g., "Caller Details" becomes caller_details). You find these by using the g_form.getSectionNames() API in a client script for dynamic retrieval or by configuring the Form Layout to see the names.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
@sharley You don't need return in this case. Your script is correct, you probably need to check the backend value of type "A" and UI section name should be correct.
Refer: https://www.servicenow.com/community/developer-forum/get-form-section-name/m-p/1971485 explanation for section names
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3m ago
Hello @sharley ,
This is the corrected Client Script.
Here, I’ve used city instead of type. If city == 'pune', then only Section A will be shown. You can modify this logic as per your requirement.
In your case:
Select field → type
Client Script type → onChange
Section name → use lowercase backend name
Issues in your original code:
You used onLoad instead of onChange.
You assigned a value using = instead of comparing using ==.
The main logic was written inside the isLoading condition, which should be outside.