How to Hide/Show choice in Multiple choice variable based on other variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2022 04:43 AM
Hello Team,
I have requirement to hide/show the one choice in Multiple choice variable in catalog item.
Two variables we have,
1. checklist (name : Virtual meeting).
2. Multiple choice : It has below three choices
1.AB
2.BA
3.CD
when I select the checklist (Virtual meeting) "BA" has to hide.
when I unselect the checklist (Virtual meeting) "BA" has to show.
Please help me on this requirement.
@Mohith Devatte
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2022 05:01 AM
Hello @vinod9 ,
you can write an on change client script on your check box variable and your script can be like this
In clear options field name put the select box field backend name
In field name of addOption method put the field name of the select box
In the choice value put the choice value of your options your want to add when virtual meeting is true(under if loop) , In choice label put the choice labels that you want to add and target index is nothing but the position of the choice
And in else loop do the exact opposite way by clearing the options again and adding all three options if its false
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if(newValue==true || newValue=='true')
{
g_form.clearOptions('<FIELD_NAME>');
g_form.addOption(<fieldName>, <choiceValue>, <choiceLabel>, <targetIndex>);
g_form.addOption(<fieldName>, <choiceValue>, <choiceLabel>, <targetIndex>);
}
else {
g_form.clearOptions('<FIELD_NAME>');
g_form.addOption(<fieldName>, <choiceValue>, <choiceLabel>, <targetIndex>);
g_form.addOption(<fieldName>, <choiceValue>, <choiceLabel>, <targetIndex>);
g_form.addOption(<fieldName>, <choiceValue>, <choiceLabel>, <targetIndex>);
}
}
Hope this helps
Mark my answer correct if this helps you
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2022 01:18 AM
@Mohith Devatte @AnubhavRitolia
I'm using this code, it's working fine, when I select the variable another field is hiding but when I unselect it, I'm not getting back hiden field.
If part is working but else part not working. Please help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2022 02:25 AM
Hello @vinod9 ,
if you are trying to hide a field based on a condition then don't user getControl. It might not work in portal
use g_form.setDisplay('your_field_name',false);
Hope this helps
Mark my answer correct if this helps you
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2022 02:30 AM
Hi @vinod9
Please try to replace '||' to '&&" online line 21:
else if (types !=true && types!='true') {
Try if this helps.
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023