The CreatorCon Call for Content is officially open! Get started here.

Trouble Resetting Conditional Subcategory Fields in Service Catalog Item Form

Sysop
Tera Contributor

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.

Sysop_0-1689961308240.png

 

 

Sysop_1-1689961336407.png

 

 

Sysop_2-1689961355545.png



Sysop_3-1689961382149.png

 

 

5 REPLIES 5

Community Alums
Not applicable

Hi, @Sysop 

We can achieve this by using the onChange client script.

Configure the client like below on the variable 'AllyDVM Operational Comms'. 

PrasadS_0-1690366498360.png

 

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