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
10-10-2017 04:26 AM
Hi Vipul,
I don't see the variable "category" defined anywhere, first define category and then use the below code to hide or display sections.
var sections = g_form.getSections();
if (newValue == '2') {
g_form.setSectionDisplay(sections[1], false);
} else {
g_form.setSectionDisplay(sections[1], true);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2017 04:27 AM
Hey Vipul,
Could you please try :
function onLoad() {
var sections = g_form.getSections();
if (g_form.getValue('category') == 'SERVER') {
sections[1].style.display = 'block';
sections[2].style.display = 'block';
} else {
sections[3].style.display = 'none';
sections[4].style.display = 'none';
}
Let me know if this was helpful/correct
Have a wonderful day ahead
Regards,
Divya Mishra
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2022 11:40 PM
Hi ,
Client Script is one of the important part of the Servicenow.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2022 12:43 AM
I think there are two things that you need to do here:
1. Onload client script, to hide section when the form loads based on category.
2. OnChange client script, to hide section, when somebody changes the category on the form.
Aman Kumar