- 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:33 AM
Thank very much - it works.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2024 07:21 AM
I was led to this post from one I made trying to do something similar. My Post
I'm using logic on an onChange Client Script exactly like the script @Voona Rohila suggested, but there seems to be something in the system that is overwriting the logic as soon as it runs.
I want the choices in Subcategory to change based on the value in Incident Type, but whenever the Client Script runs, it seems like something else overwrites the changes to Subcategory almost immediately.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
g_form.clearOptions('subcategory');
g_form.addOption('subcategory', '', '-- None --', 100);
if (g_form.getValue('category') == 'Hardware' && g_form.getValue('u_incident_type') == 'Dental') {
g_form.removeOption('subcategory', 'Cable Box');
g_form.removeOption('subcategory', 'Computer');
g_form.addOption('subcategory', 'test', 'Test', 100);
}
}
It's as if the dependent value setting is overwriting the script. Subcategory has a Dependent Value of Category, and Category has a Dependent Value of Incident Type. When the Category is the same for every Incident Type, you can't limit the choices for Subcategory. I want a specific list of choices for Subcategory based on the Incident Type and Category. If I have Incident Type as 'Dental' and Category as 'Hardware' I should get specific list of choices for Subcategory, and the same should be true if I pick Incident Type as 'IT' and Category as 'Hardware', but because Subcategory is Dependent on Category, the clearOptions, removeOption, and addOption functions seem to get overwritten and all choices under 'Hardware' are still available not matter what the Incident Type is.