Change choice list in incident form through Client Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2023 03:52 AM - edited 11-21-2023 04:04 AM
I have got a good amount of data in category and subcategory. For below code clarification, Subcategory is dependent on Category and Category is dependent on Services (Reference field). So, when I have same category for different services the subcategory adds up for all services i.e.
- Desktop Services (Service)
- Bloomberg (Category)
- Access (Subcategory)
- Test (Subcategory)
- Bloomberg (Category)
- Market Intelligence (Service)
- Bloomberg (Category)
- User Permission (Subcategory)
- Bloomberg (Category)
For this when I select Desktop Services as Service and Bloomberg as Category, it shows following options:
- Access (Subcategory)
- Test (Subcategory)
- User Permission (Subcategory)
How can I change this dynamically based on Service? Below I have written a script and It is not changing the choice list.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var services = g_form.getValue('business_service');
//alert(services);
if (newValue == 'bloomberg' && services=='42d08ef81ba2b5104d5920a2b24bcbd6') {
alert('desktop services');
g_form.clearOptions('u_subcategory');
g_form.addOption('u_subcategory', 'Access', 'access');
g_form.addOption('u_subcategory', 'test', 'test');
//g_form.removeOption('u_subcategory','user_permission');
}
else if (newValue == 'bloomberg' && services=='22d0cef81ba2b5104d5920a2b24bcb16') {
alert('Market Intelligence');
g_form.clearOptions('u_subcategory');
g_form.addOption('u_subcategory', 'User Permission', 'user_permission');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2023 03:50 AM
I don't see any logic in the posted version of your script that would clear without adding. Try wrapping the var services line to the end in one setInterval function, rather than having one for each if block - and maybe 2 seconds is longer than necessary to wait, so you can try lowering the ending argument to 1000 or even 500.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2023 06:06 AM
For the script part I was just testing it so I commented and tested it but none of the functions were working (Is it because of dependent field value is there?). I have tried it with lowering time, but it is just refreshing for the rest every time and not letting me select.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2023 09:09 AM
I'm not following - if the entire script inside the onChange function is in one setInterval function it is not removing any options, or is still removing them all when there are repetitive Service/Category changes?