- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2022 08:27 AM
Hi everyone,
I have a requirement that a form section is only display when I select a specific choice in a choice field otherwise the should be hidden.
I created a on change client script but its not working. The section is displayed and when a select "SLIR" choice the section is hidden?? What could be the problem?
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var select=g_form.getValue('u_themeselection');
if(select=='SLIR')
{
g_form.setSectionDisplay('slir', true);
}
else{
g_form.setSectionDisplay('slir', false);
}
}
Thanks for your hep.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2022 08:08 PM
You can write 2 client scripts:
- OnLoad of form where you can hide the section.
- OnChange of choice field where you can check choice value and show the section.
Or you can also have only the OnChange client script if you always want to hide the section even choice value is SLIR
Just one question, do you also want to hide the section on the load of the form even if the choice is "SLIR" in the backend (database)?
Regards,
Reshma
**Please mark my answer correct or helpful based on the impact**
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2022 08:32 AM
Hello @JohnDF Please verify with some alerts that the value that you are getting from getValue is correct, also verify if it is going inside the if & else block.
Also, go through the below article.
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0696583
Please mark this as a Helpful / Accepted Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2022 08:33 AM
Make sure there aren't any mandatory fields in that sections. It won't hide the section if there are mandatory fields.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2022 11:27 AM
Hi @JohnDF , I tried the same on incident table and my code is working fine.
- Check field name is correct or not. Use 'newValue' instead.
- Check the section name, for example Section name is 'Show Section' then we should use the name 'show_section'.
- Check for any mandatory fields.
Regards,
Reshma
**Please mark my answer correct or helpful based on the impact**
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2022 01:12 PM
Thanks for your reply. I guess you didnt understand me right.
The section should be hidden when I load the form, only when I select on the frm the choice "SLIR" in the choice fild than the tab should be visible.
Hopefully its now clear.