Dependent field and Client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2022 05:29 AM
Hi,
I have 2 fields, category and subcategory, Subcategory is a dependent field on category.
on the basis of category options, subcategory options will be visible.
Now I need to add one more choice in subcategory with the help of onchange client script.
I have written code like
var cat = g_form.getValue('category');
if(cat == 'A' || cat == 'B'){
g_form.clearOptions('subcategory);
g_form.addOptions('subcategory', '1', 'ABC');
}
This script is not working as we already have some dependence on the category field.
As soon as I select A or B in category field, it shows ABC value in subcategory for miliseconds and then again back to the dependency choice options present in dictionary.
Also , does clearOption method has to be used before addOptions method? because if i remove clearOptions then it does not even work for miliseconds as well.
Any suggestions on this? Please help.
I CANNOT add another option is subcategory field itself- this is important.
I have to use onchange client script for this.
Need advice on this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2022 05:45 AM
Hi @Udit5
I would suggest using the OOB dependent field functionality. Please explore the below links:
https://www.servicenow.com/community/developer-forum/how-to-configure-dependent-values/m-p/2004166
Please mark my answer as correct if this helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2024 12:07 AM
Facing the same issue, were you able to get a solution on this.
I tried to setTimeout, but that sometime works and sometimes doesnt.