- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2017 02:17 AM
I have a requirement to only show "Closure Information" section when the state is closed. For that i have the following code but when i change state from closed to a different state, the section is still displayed
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var state = g_form.getValue('state');
if(state == "7"){
g_form.setSectionDisplay('closure_information',true);
}
if (state != "7"){
g_form.setSectionDisplay('closure_information',false);
}
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2017 02:31 AM
And also make sure you dont have any mandatory fields over there. It will not work if you have any
Harish

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2017 02:22 AM
Comment this code or remove isLoading and check
if (isLoading || newValue === '') {
return;
}
Harish

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2017 02:24 AM
Try this,
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var state = g_form.getValue('state');
if(state == "7"){
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
06-13-2017 02:25 AM
Hi,
This link might be helpful
https://www.servicenowguru.com/scripting/client-scripts-scripting/showhide-form-section/

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2017 02:27 AM
Hello Jao,
Try modifying the code as below
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if(newValue!= oldValue && newValue != '')
{
var state = g_form.getValue('state');
if(state == "7"){
g_form.setSectionDisplay('closure_information',true);
}
else{
g_form.setSectionDisplay('closure_information',false);
}
}
}