Client script: Show "Resolution Code" choices based on Category
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2022 03:46 AM
Dear experts,
I've tried to use "Dependent fields/value" to make some choices of the "Resolution Code" field become available or hidden, based on what category my Case (CSM) is on.
I found through posts like Add multiple dependants in field for Choice - IT Service Management - Question - ServiceNow Communit... that you cannot add multiple dependants for a choice, which is what I require.
Since I am not yet proficient in scripting, I was hoping someone could help me write a client script that does the following:
- When Category is set to choice "Normal Change" (value 6), show "Resolution Code" choices 17 & 18 (values)
- When Category choice is set to anything else, show all other choices (0 4 3 5 7 8 9), except 17 & 18.
I tried to leave the "dependant value" empty, but this only resolves in the other choices to show when Category is set to "None". Hence I figured I need a client script! I see however many warnings about client scripts; will this be impactful on our performance and hence not-advisable? Are there any alternatives?
Thank you kindly for the help!
Kind regards,
Marissa Nijhof
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2022 04:13 AM
Hi,
you can achieve with the UI policy.
Condition if Category is one of these choices - 0 4 3 5 7 8 9 then use script to remove the choices of "Resolution Code" choices 17 & 18.
on else remove the "Resolution Code" other choices like 1, 2, 3,4 etc
on Execute if true section use this
function onCondition() {
g_form.removeOption('category', '17');
g_form.removeOption('category', '18');
}
on section use below code and add other choices as well.
function onCondition() {
g_form.removeOption('category', '1');
g_form.removeOption('category', '2');
g_form.removeOption('category', '3');
g_form.removeOption('category', '4');
g_form.removeOption('category', '5');
g_form.removeOption('category', '6');
g_form.removeOption('category', '7');
g_form.removeOption('category', '8');
}
Thanks,
Pavankumar
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2022 04:18 AM
Hi,
You can achieve with the UI policy.
Create UI policy on when to Apply add Condition as Category is one of these choices - 0 4 3 5 7 8 9 then use script to remove the choices of "Resolution Code" choices 17 & 18.
on else remove the "Resolution Code" other choices like 1, 2, 3,4 etc
on Execute if true section use this
function onCondition() {
g_form.removeOption('category', '17');
g_form.removeOption('category', '18');
}
on Execute if false section use below code and add other choices as well.
function onCondition() {
g_form.removeOption('category', '1');
g_form.removeOption('category', '2');
g_form.removeOption('category', '3');
g_form.removeOption('category', '4');
g_form.removeOption('category', '5');
g_form.removeOption('category', '6');
g_form.removeOption('category', '7');
g_form.removeOption('category', '8');
}
Thanks,
Pavankumar
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2022 02:52 AM
Dear Pavan,
Thank you for the suggestion! I've created the UI Policy with the script you gave me, but even though it seems to work on initial load, as soon as I change the category, the resolution codes come up empty.
(By the way, I noticed you used 'category' in your script, which removed category options. I changed this to 'resolution_code')
I hope you can point out the mistake I made!
Result when setting to category "Question"
Thank you in advance for the big help.
Kr,
Marissa
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2022 08:41 AM
Hi,
On UI Policy form you can uncheck the On load check box it will executes like onchange.
Hope it helps!!
Please Mark ✅ Correct, Thanks!!
Regards
Pavankumar
ServiceNow Community MVP 2024.
Thanks,
Pavankumar