i have a requirement on state field

Trupti Krishnam
Tera Contributor

I have a requirement on state field ., The state field has almost 50 choices ..I have another variable [ABC]  where the state field is dependent on .That Variable has 4 choices On selecting one of its choice it should show only 2 choices of the state variable and on selecting other Choice of the variable ABC it should return all the variable .. I have written the below code. 

 if (newValue == 'house_hold') {
        g_form.clearOptions('state');
        g_form.addOption('state', '', '-- None --');
        g_form.addOption('state', 'UT', 'UT');
        g_form.addOption('state', 'CO', 'CO');
    } 
but i m not exactly how to write the else condition so that it shows all the existing choices..,
1 REPLY 1

Vishal Birajdar
Giga Sage

Hi @Trupti Krishnam 

 

Can you try like this...!!

 

 if (newValue == 'house_hold') {
       /*Remove the other options (46) only*/
       g_form.removeOption('field_name','choice_1');
       g_form.removeOption('field_name','choice_2');
        //& so on 
    } else {
        /*If oldValue was 'house_hold'*/
        if(oldValue == ''house_hold'){ 
                  g_form.addOption('field_name','choice_1','choice_1');
                  g_form.addOption('field_name','choice_2','choice_2');   
                  // & so on
        }
}

 

 

 

 

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates