Show/Hide Form Section
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-19-2013 01:26 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-19-2013 02:04 PM
Hi Rachelle,
I can't find anything wrong with the script. may be you are not using the right section number inside [].
So try with diffrent numbers like sections[2].style.display or sections[3].style.display etc.
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2013 11:49 AM
Thanks! But I did check the form section number. Very Odd, do you know of another solution?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-24-2013 12:16 AM
Hi Rachelle,
I just tried it on https://demo019.service-now.com/navpage.do. Its working good. Please check it on incident form, where I wrote the below on change script on field - Contact-type. Based on the value selected, section will get display. For Eg: If we choose Email , section-email will appear.
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 == 'email') {
sections[4].style.display = 'block';
} else {
sections[4].style.display = 'none';
}
if (newValue == 'phone') {
sections[5].style.display = 'block';
} else {
sections[5].style.display = 'none';
}
if (newValue == 'self-service') {
sections[6].style.display = 'block';
} else {
sections[6].style.display = 'none';
}
}
I hope this would provide you some direction.
Note : Please check if you are comparing the database value, not the Label Name in the IF Statement
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-25-2013 06:54 AM
Thank you Neetu!