Hi Community..i need to populate the drop down list based on the another dropdown value.Please help me out.

Nana5
Mega Guru

Hi Community..i need to populate the drop down list based on the another dropdown   value.Please help me out.

example: there is drop down called state, if user will select the state(eg:karnataka), then in below drop down i need to display all the district of that state.Please help me in this.Thanjks

1 ACCEPTED SOLUTION

Nana5
Mega Guru

Hi All


I have done using client script


function onChange(control, oldValue, newValue, isLoading) {


  if (isLoading || newValue == '') {


  return;


  }


  var u_ent = g_form.getValue('u_entity');


  alert(u_ent);



  if(newValue == 'Austria'){



  var dVals = '20,21,22,24,60,70,90';


  var dOpts = dVals.split(',');


  var myIndex = 1;



  //housekeeping, clear values in case this is used onchange


  g_form.clearValue('u_tax_code_sub');


  g_form.clearOptions('u_tax_code_sub');



  //Add the standard none option


  g_form.addOption('u_tax_code_sub', '-- None --', '-- None --', 1);



  for (i = 0; i <   dOpts.length; i++) {


  myIndex++;


  g_form.addOption('u_tax_code_sub',   dOpts[i],   dOpts[i], myIndex);



  }


}


if(newValue == 'Belgium Sales Company'||newValue == 'Belgium Plant'){



  var u_code = 'V0,V1,V2,V3,V4,V5,V6,VA,VB,VC,VD,VE,VF';


  var u_split = u_code.split(',');


  var myIndex1 = 1;



  //housekeeping, clear values in case this is used onchange


  g_form.clearValue('u_tax_code_sub');


  g_form.clearOptions('u_tax_code_sub');



  //Add the standard none option


  g_form.addOption('u_tax_code_sub', '-- None --', '-- None --', 1);



  for (i = 0; i <   u_split.length; i++) {


  myIndex1++;


  g_form.addOption('u_tax_code_sub',   u_split[i],   u_split[i], myIndex1);



  }


}


if(newValue == 'Sweden Sales Company'){



  var u_code1 = '21,22,23,60,70,80,90';


  var u_split1 = u_code1.split(',');


  var myIndex2 = 1;



  //housekeeping, clear values in case this is used onchange


  g_form.clearValue('u_tax_code_sub');


  g_form.clearOptions('u_tax_code_sub');



  //Add the standard none option


  g_form.addOption('u_tax_code_sub', '-- None --', '-- None --', 1);



  for (i = 0; i <   u_split1.length; i++) {


  myIndex1++;


  g_form.addOption('u_tax_code_sub',   u_split1[i],   u_split1[i], myIndex2);



  }


}


if(newValue == 'Spain'){



  var u_code2 = 'R0,R7';


  var u_split2 = u_code1.split(',');


  var myIndex3 = 1;



  //housekeeping, clear values in case this is used onchange


  g_form.clearValue('u_tax_code_sub');


  g_form.clearOptions('u_tax_code_sub');



  //Add the standard none option


  g_form.addOption('u_tax_code_sub', '-- None --', '-- None --', 1);



  for (i = 0; i <   u_split2.length; i++) {


  myIndex1++;


  g_form.addOption('u_tax_code_sub',   u_split2[i],   u_split2[i], myIndex3);



  }


}







}


View solution in original post

10 REPLIES 10

You can have both the options. Find the screenshots below:



1. Different choices with same dependent value.


Capture.JPG



2. Same choice with different dependent value.


Capture1.JPG


Akshay14
Tera Guru

Hi Prakash,


You could do it by another way. Try using following steps.


Step 1 - In 1st drop-down field(eg : category in my case) select the value on which your second drop-down field(Subcategory) choices are need to pop up.


                        in category I have selected the software.


Step 2 - Now right click on the 2nd drop-down field and go to configure choices. And add the choices you want. This choices will only populate when you select                                                 software in your first drop-down field.


find_real_file.png


Geoffrey2
ServiceNow Employee
ServiceNow Employee

Everyone else is correct. So here are some visual aids



1) Create 2 Choice fields, State and District


Screen Shot 2016-09-12 at 9.36.47 PM.png


2) Right-click on the State label and select Configure Choices


Screen Shot 2016-09-12 at 9.37.24 PM.png


3) Populate your list of States


Screen Shot 2016-09-12 at 9.38.39 PM.png


4) Right-click on the label of the District field and select Configure Dictionary


5) In the Related Links list, click Advanced View. This will show the Dependent field tab.


Screen Shot 2016-09-12 at 9.41.27 PM.png


6) Select State in Dependant on field


Screen Shot 2016-09-12 at 9.41.51 PM.png


7) Go back to the form and select the first state in the State field. Then right-click on the label of the District field and select Configure Choices


Screen Shot 2016-09-12 at 9.53.27 PM.png


😎 Populate the Districts for this State. Once complete, go back to the form and select the next state and repeat.


Screen Shot 2016-09-12 at 9.43.48 PM.png


9) Now when you select a State, the values in District will update automatically.


Screen Shot 2016-09-12 at 9.44.12 PM.png


Nana5
Mega Guru

Hi All


I have done using client script


function onChange(control, oldValue, newValue, isLoading) {


  if (isLoading || newValue == '') {


  return;


  }


  var u_ent = g_form.getValue('u_entity');


  alert(u_ent);



  if(newValue == 'Austria'){



  var dVals = '20,21,22,24,60,70,90';


  var dOpts = dVals.split(',');


  var myIndex = 1;



  //housekeeping, clear values in case this is used onchange


  g_form.clearValue('u_tax_code_sub');


  g_form.clearOptions('u_tax_code_sub');



  //Add the standard none option


  g_form.addOption('u_tax_code_sub', '-- None --', '-- None --', 1);



  for (i = 0; i <   dOpts.length; i++) {


  myIndex++;


  g_form.addOption('u_tax_code_sub',   dOpts[i],   dOpts[i], myIndex);



  }


}


if(newValue == 'Belgium Sales Company'||newValue == 'Belgium Plant'){



  var u_code = 'V0,V1,V2,V3,V4,V5,V6,VA,VB,VC,VD,VE,VF';


  var u_split = u_code.split(',');


  var myIndex1 = 1;



  //housekeeping, clear values in case this is used onchange


  g_form.clearValue('u_tax_code_sub');


  g_form.clearOptions('u_tax_code_sub');



  //Add the standard none option


  g_form.addOption('u_tax_code_sub', '-- None --', '-- None --', 1);



  for (i = 0; i <   u_split.length; i++) {


  myIndex1++;


  g_form.addOption('u_tax_code_sub',   u_split[i],   u_split[i], myIndex1);



  }


}


if(newValue == 'Sweden Sales Company'){



  var u_code1 = '21,22,23,60,70,80,90';


  var u_split1 = u_code1.split(',');


  var myIndex2 = 1;



  //housekeeping, clear values in case this is used onchange


  g_form.clearValue('u_tax_code_sub');


  g_form.clearOptions('u_tax_code_sub');



  //Add the standard none option


  g_form.addOption('u_tax_code_sub', '-- None --', '-- None --', 1);



  for (i = 0; i <   u_split1.length; i++) {


  myIndex1++;


  g_form.addOption('u_tax_code_sub',   u_split1[i],   u_split1[i], myIndex2);



  }


}


if(newValue == 'Spain'){



  var u_code2 = 'R0,R7';


  var u_split2 = u_code1.split(',');


  var myIndex3 = 1;



  //housekeeping, clear values in case this is used onchange


  g_form.clearValue('u_tax_code_sub');


  g_form.clearOptions('u_tax_code_sub');



  //Add the standard none option


  g_form.addOption('u_tax_code_sub', '-- None --', '-- None --', 1);



  for (i = 0; i <   u_split2.length; i++) {


  myIndex1++;


  g_form.addOption('u_tax_code_sub',   u_split2[i],   u_split2[i], myIndex3);



  }


}







}


Geoffrey2
ServiceNow Employee
ServiceNow Employee

You just rebuilt existing functionality, but made it harder to maintain.