- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2017 03:26 PM
The requirement is : On the incident form , Closure Information Tab should not show until resolved state is selected. I need to have the name of the section , not the label. In my code I wrote the label , that's why it's not working. my question is how to get the name??
This is my onchange client script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var sections = g_form.getSections();
if(newValue=='Resolved')
{
g_form.setSectionDisplay('Closure Information', true);
}
else {
g_form.setSectionDisplay('Closure Information', false);
}
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-03-2017 03:05 PM
Did you try changing the value of state..?
Existing script will not work for form loading if you want to run this script even when the form loads then you need to remove isLoading from the if condition
Here is the script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if ( newValue === '') {
return;
}
if(newValue=='6')
{
g_form.setSectionDisplay('closure_information', true);
}
else {
g_form.setSectionDisplay('closure_information', false);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2017 03:37 PM
Try:
g_form.setSectionDisplay('closure_information', false);
Refer to: GlideForm (g form) - ServiceNow Wiki

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2017 08:34 PM
//Here you go
//Tested
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var stateValue = g_form.getValue('state');
alert(stateValue);
var sections = g_form.getSections();
if(stateValue == '6') //resolved
{
alert("inside");
sections[3].style.display = 'none'; //section 3 indicates Closure information
//g_form.setSectionDisplay('Closure Information', false);
}
else
{
alert("else");
sections[3].style.display = 'block';
}
}
NOTE: make sure you donot have any mandatory fields to hide section
Harish

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2017 08:42 PM
Hi Soni,
You did write approach but you used "Form Section" name in InIt caps. name should be in small letter and there should not be any space. your section name will be
"closure_information".
Please try with below code. i have updated ur script.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var sections = g_form.getSections();
if(newValue=='Resolved')
{
g_form.setSectionDisplay('closure_information', true);
}
else {
g_form.setSectionDisplay('closure_information', false);
}}
Also for some form section details, please refere the below thread.
Hide section in Incident Table
Thanks,
Harshvardhan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-19-2018 07:19 PM
Thanks, mate, I had a 3 word Form section and was pulling my hair out to why it wasn't working!