Show/Hide Form Section

rsanon
Tera Contributor

Does anyone know how to Hide/Show a form section based on a field. I attempted to follow the example below from the wiki, but it did not work for me. See attached.

function onChange(control, oldValue, newValue, isLoading) {
//this example was run on a form divided into sections (Change form)
// and hid a section when the "state" field was changed
var sections = g_form.getSections();
if (newValue == '2') {
sections[1].style.display = 'none';
} else {
sections[1].style.display = 'block';
}
}
http://wiki.servicenow.com/index.php?title=GlideForm_(g_form)#Form_Information_Methods

15 REPLIES 15

neetusingh
Giga Guru

Hi Wamiq,

I have done the same thing on https://demo019.service-now.com/navpage.do on incident table.

Please refer below code for doing the needful :
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
var sections = g_form.getSections();
if (newValue == 6) {
sections[4].style.display = 'block';
} else {
sections[4].style.display = 'none';
}
}

// Onchange script is running on "State" field. Here '6' is the database value for state - "Resolved" on incident form. And '4' is the array position of section - 'xyz'.

Please check in your script if you are mentioning the correct database value for Resolved State and correct array position of section.

Regards/Neetu
Happy to help!!!!


Thanks Neetu.

It's working now. Any logic how we get the correct index number?


neetusingh
Giga Guru

Hi Wamiq,

We can get the correct index number for the sections from the Forms Module. Type 'forms' in application navigator, then look for incident table, here you can see all the sections associated with the incident table with the defined array position. Refer screenshot for further clarifications!!!!!!!

Regards/Neetu


Awesome.. Thank you so much..

Have a great day 🙂
Wamiq


deepakvednegi
Giga Contributor

There is a requirement that just hide the content of column of a section...Like in related list of problem,i just want to hide the incident number but its reference icon must be there