Trouble Resetting Conditional Subcategory Fields in Service Catalog Item Form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2023 10:44 AM
Hello,
I'm currently developing a Service Catalog form in ServiceNow and have come across a challenge. First off this is a record producer. My form has a field named 'u_request_type' (a drop-down list with choices, one of which is 'AllyDVM Operational Comms') and another field named 'ally_subcategory' (also a drop-down list with multiple choices).
My objective is:
If the user changes the selection in 'u_request_type' away from 'AllyDVM Operational Comms', to another answer, I want the 'ally_subcategory' field to reset back to 'none', meaning it should not retain the previous selection. On the variable form for 'ally_subcategory' under "Type Specifications" I do have the "include none" box checked and --None-- is a selectable option.
To achieve this, I tried implementing a Catalog Client Script. Here's the script I used:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (newValue != 'AllyDVM Operational Comms') {
producer.ally_subcategory = '';
}
}
Despite this, the script doesn't seem to be working as I expected. The 'ally_subcategory' field still holds onto its prior selection when 'u_support_type' is switched away from 'AllyDVM Operational Comms'.
Here are some screenshots.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2023 03:18 AM
Hi, @Sysop
We can achieve this by using the onChange client script.
Configure the client like below on the variable 'AllyDVM Operational Comms'.
Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
if (newValue != 'AllyDVM Operational Comms') {
g_form.setValue('ally_subcategory','');
}
}
Note: Deactivate other unnecessary client scripts and UI policies.
If this helped you in any way, please hit the like button/mark it helpful. Also, don't forget to accept it as a solution. So it will help others to get the correct solution.
thanks,
Prasad