- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2022 05:37 AM
Hello all,
I have created a catalog item and there is a requirement to show the option in the select box based on the variable.
The variable name are "model_category" & "form_factor". I have created the following OnChange client script and it work but the problem is if the requester change to other option in the model_category the form_factor does not updated.
if (g_form.getValue('model_category') == 'computer') {
g_form.removeOption('form_factor', 'smart_phone');
g_form.removeOption('form_factor', 'tablet');
} else if (g_form.getValue('model_category') == 'mobile_device') {
g_form.removeOption('form_factor', 'desktop');
g_form.removeOption('form_factor', 'laptop');
}
Regards,
Hong
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2022 06:27 AM
Hi hongsok
since you are the options the options need to be added again.
Try this
g_form.clearOptions('form_factor');
g_form.addOption('form_factor','','-- None --',100)
if (g_form.getValue('model_category') == 'computer') {
g_form.removeOption('form_factor', 'smart_phone');
g_form.removeOption('form_factor', 'tablet');
g_form.addOption('form_factor','laptop','Laptop',100);
g_form.addOption('form_factor','desktop','Desktop',200);
} else if (g_form.getValue('model_category') == 'mobile_device') {
g_form.removeOption('form_factor', 'desktop');
g_form.removeOption('form_factor', 'laptop');
g_form.addOption('form_factor','smart_phone','Smart Phone',300);
g_form.addOption('form_factor','tablet','Tablet',400);
}
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2022 06:21 AM
Hi,
are you using correct choice value during removal of option?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2022 06:34 AM
Yes. Rohila's script is working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2022 06:36 AM
Hi,
Nice to know.
1) clear the options when onchange works
2) then add options which you require instead of removing
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2022 06:27 AM
Hi hongsok
since you are the options the options need to be added again.
Try this
g_form.clearOptions('form_factor');
g_form.addOption('form_factor','','-- None --',100)
if (g_form.getValue('model_category') == 'computer') {
g_form.removeOption('form_factor', 'smart_phone');
g_form.removeOption('form_factor', 'tablet');
g_form.addOption('form_factor','laptop','Laptop',100);
g_form.addOption('form_factor','desktop','Desktop',200);
} else if (g_form.getValue('model_category') == 'mobile_device') {
g_form.removeOption('form_factor', 'desktop');
g_form.removeOption('form_factor', 'laptop');
g_form.addOption('form_factor','smart_phone','Smart Phone',300);
g_form.addOption('form_factor','tablet','Tablet',400);
}
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP