Onload Client Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2017 04:22 AM
function onLoad() {
var sections = g_form.getSections();
if (category== 'SERVER') {
sections[1].style.display = 'block';
sections[2].style.display = 'block';
} else {
sections[3].style.display = 'none';
sections[4].style.display = 'none';
}
}
Please help in the correction of this code. I would like to display the section based on"category" in maintain item form but it is not working. Once I removed the "if else" condition then it is working .

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2022 05:44 AM
Hi Vipultiwar01,
Set a default value on Field "catalog" and create an onChange() script on field "catalog".
I've used g_form.setSectionDisplay() to show or hide sections. I'm also comparing with "server" instead of "SERVER" because ServiceNow converts values to lowercase. The label name is "SERVER" but the value is "server".
onChange Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (newValue == '' || oldValue == newValue) {
return;
}
if (newValue == 'server') {
g_form.setSectionDisplay('section1', true);
g_form.setSectionDisplay('section2', true);
g_form.setSectionDisplay('section3', false);
g_form.setSectionDisplay('section4', false);
} else {
g_form.setSectionDisplay('section1', false);
g_form.setSectionDisplay('section2', false);
g_form.setSectionDisplay('section3', true);
g_form.setSectionDisplay('section4', true);
}
}
Execution results
1. Case when the form is opened. I've set the category to default to "SERVER"
2. Case when "OTHER" is selected.