Show/hide section with onChange client script

joaosantos
Mega Expert

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);

}

   

}

1 ACCEPTED SOLUTION

Harish KM
Kilo Patron
Kilo Patron

And also make sure you dont have any mandatory fields over there. It will not work if you have any


Regards
Harish

View solution in original post

6 REPLIES 6

Harish KM
Kilo Patron
Kilo Patron

And also make sure you dont have any mandatory fields over there. It will not work if you have any


Regards
Harish

BillMartin
Mega Sage

if you want to watch it live, on how to hide sections. you view my video here: 

 

 

You can also read the full article here to give you a picture and a firm understanding of how the g_form object works. [Article] How to Hide a Section in ServiceNow Using Client Script: A Beginner-Friendly Guide