Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Select box dependent on another select box option

Jonathan Joaqui
Tera Contributor

Hi,

 

I have 2 select boxes and I need the 2nd select box dependent on the 1st select box.

 

Ex: If I choose 1 on the first select box then it should only show A on the second select box as an option

      If I choose 2 on the first select box then it should only show B and C as the options for the second select box (A should not be part of the option).

 

I need this without creating tables or such.

 

Is it possible?

3 REPLIES 3

Community Alums
Not applicable

Hi,

You can write onChange Client Script on the 1st Select box.

You can use g_form.addOption() and g_form.removeOption() based on the selection in onChange Script

 

Regards,

Karthik R

Community Alums
Not applicable

Onchange client script on the First Select box

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    //Type appropriate comment here, and begin script below
    if (newValue == 'Type1') {                                         // For 1st choice only option 'A' is added
        g_form.addOption('Testbox', 'A', 'a');                    //Fieldname,Nameofthechoice,value
        g_form.removeOption('Testbox', 'B', 'b');
        g_form.removeOption('Testbox', 'C', 'c');
        g_form.removeOption('Testbox', 'D', 'd');
    }
    if (newValue == 'Type2') {                                       //For choice 2  option 'B', 'C' are shown
        g_form.addOption('Testbox','B','b');
        g_form.addOption('Testbox','C','c');
        g_form.removeOption('Testbox','A','a');
        g_form.removeOption('Testbox','D','d');
    }
}

HI Karthik,

 

 

I messaged you the output.

 

Thanks,

 

Jonathan