Need to display the select box values based on another select box
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2017 02:26 AM
Hi
please help me to display the select box values based on another select box in a catalog item form.
for example i need to display the "states" based on "country" in catalog item form... please help me..
Regards
venky
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2017 02:32 AM
Hi Venkatesh,
You can see a sample script in wiki: http://wiki.servicenow.com/index.php?title=Adding_Dependent_Variables#gsc.tab=0
You need to change your query accordingly to query all states from a country and add it is an option in your select box. The sample uses GlideRecord but you should be changing it to Glide Ajax for better performance
Thanks
Please Hit like, Helpful or Correct depending on the impact of the response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2017 04:25 AM
Hi,
this is very usefull.
i tryed this,
in 1st dropdown i am getting default value and in 2nd one i am getting all the fields in first time
is there any solution to remove the options on 2nd dropdown at the time of loading.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2017 04:29 AM
Hi Venkatesh,
Have your checked the last para in http://wiki.servicenow.com/index.php?title=Adding_Dependent_Variables#Additional_OnLoad_script_to_in...
You can try this out.
function onLoad (control, oldValue, newValue, isLoading) {
// Used the g_form.clearOptions() function instead of g_form.removeOption() function
g_form.clearOptions('subcat');
}
If my response have answered your query, request you to mark it as correct answer so we can close the thread and others can refer
Thanks
Please Hit like, Helpful or Correct depending on the impact of the response

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2017 02:41 AM
You can write onchange client script on variable country. So when you change the country. state shud change.
/Code
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
g_form.clearOptions('city');
var getCountry = g_form.getValue('country'); // country is variable name
alert(getCountry);
if(getCountry=='India')
{
g_form.addOption('city','Bangalore','Bangalore'); // city is variable name, bangalore is the choices in your select box
g_form.addOption('city','Chennai',' Chennai');
}
//Type appropriate comment here, and begin script below
else if(getCountry=='Aus')
{
g_form.addOption('city','Brisbane','Brisbane');
}
}
Harish