- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2017 01:18 AM
I have two variables Country and state(variable name also same country and state), Both are drop down variables.Country has 3 options Australia, India, China. I need to provide state dropdown option based on the country selected
if country = Australia state options should be Australian Capital Territory, New South Wales, Northern Territory, South Australia, Queensland, Tasmania, Victoria, Western Australia;
if country is not Australia state option should be only :Not Applicable. I thing for this catalog client script required, Please provide script for this.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2017 01:31 AM
You can use like this
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
g_form.clearOptions('state');
var val = g_form.getValue('country');
alert(val);
if(val=='Australia')
{
alert('inside');
g_form.addOption('state', '1', 'statename');
g_form.addOption('state', '2', 'statename');
}
else if(val=='India')
{
alert('inside');
g_form.addOption('state', '1', 'statename');
g_form.addOption('state', '2', 'statename');
g_form.addOption('state', '3', 'statename');
}
}
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-15-2019 01:35 AM
Hi sirsk,
For your solution, you need to define the Catalog Client Script and Script Include as below. Refer the below code snippet and tweak as per your requirement.
Catalog Client Script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Clear the options first
g_form.clearOptions('category'); //Pass the proper variable name
g_form.clearOptions('subcategory'); //Pass the proper variable name
var ga = new GlideAjax('servicecategorieslookup');
ga.addParam('sysparm_name', 'getServiceRelatedValues');
ga.addParam('sysparm_ser', newValue);
ga.getXML(retrieveValue);
}
function retrieveValue(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
answer = answer.evalJSON();
g_form.addOption('category', answer.cat, answer.cat); //Pass the proper variable name
g_form.addOption('subcategory', answer.subcat, answer.subcat); //Pass the proper variable name
}
Script Include
var servicecategorieslookup = Class.create();
servicecategorieslookup.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getServiceRelatedValues: function(){
var service = this.getParameter('sysparm_ser'); //Retrieve the value from Catalog Client Script
var gr = new GlideRecord('u_service_category_lookup'); //Pass the table name
if(gr.get(service)) {
var result = {
cat: gr.getValue('u_category'), //Pass the Category field name
subcat: gr.getValue('u_subcategory')
};
var json = new JSON();
result = json.encode(result);
return result;
}
},
type: 'servicecategorieslookup'
});
I hope this helps.Please mark correct/helpful based on impact

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2017 02:09 AM
g_form.addOption('state', '1', 'none');
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2017 02:11 AM
Yes i tried this. If i add like this form accepting none also as a state
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2017 08:21 AM
To get None to appear in your list but not to be considered a value for state use the following:
g_form.addOption('state', '', '-- None --');
Please mark as correct/helpful if you find it as such.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2017 03:21 AM
what exactly your lookin for?
None also will be a drop down value.
Harish