- 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
‎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
‎04-27-2017 02:06 AM
Hi Harish,
Your code is working well, Is it possible to add none option to the above code?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2017 01:35 AM
Hi Venkatesh,
If 'State' variable is a Reference type field referring a table which has records with States and Country then you can simply user Reference Qualifier. Please find the below helpful threads:
1. Script Include Advanced Reference Qualifier help required
2. reference selection qualfier
Or if, this are simple Choices (of having State variable a Select Box type) then you can go for Catalog Client Script on change of the Country variable and use the below function. Please refer section 12.3 in this wiki link: GlideForm (g form) - ServiceNow Wiki
g_form.removeOption('field_name', 'choiceValue');
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
‎03-13-2019 11:52 AM
HI Amlanpal,
My scenario is same like this.. Can you kindly help on this below request??
How to show "drop down" list on catalog item, on selected of one reference field variable in the catalog item (portal).
exact scenario::::
I have 3 variables in my catalog item .below are the variable details
1. service (reference) it refers to one custom table
2.category (select box)
3. sub category (select box)
for one service name there might be different categories and subcategories
for exampe
when i select test1 on the catalog item (portal) it should show all categories&subcategories dropdownrelated to that service only. if i select test2 service it should show realted categories&subcategories for that particular service.
for this i have written clientscript and script include it is setting one value default ..but i dont want to setup one value. I need to show all values in dropdown.
please find the below script which i have written..Kindly please suggest
client script@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var service = g_form.getValue('service');
if (service != '') {
var gr = new GlideAjax('servicecategorieslookup');
gr.addParam('sysparm_name', 'servicecategorieslookup');
gr.addParam('sysparm_ser', service);
gr.getXML(populate);
}
function populate(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var array = answer.split(",");
for(var i=0; i<array.length; i++) {
if (i==0)
g_form.setValue('category', array[i]);
//g_form.setReadOnly('category');
if(i==1)
g_form.setValue('subcategory', array[i]);
//g_form.setReadOnly('subcategory');
if(i==2)
g_form.setValue('assigned_group', array[i]);
}
}
//Type appropriate comment here, and begin script below
}
Script include@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
var servicecategorieslookup = Class.create();
servicecategorieslookup.prototype = Object.extendsObject(AbstractAjaxProcessor, {
servicecategorieslookup:function() {
var ser = this.getParameter('sysparm_ser');
var gr = new GlideRecord('u_service_categories_lookup');
gr.addQuery('sys_id', ser);
gr.query();
if(gr.next()) {
return gr.u_category + ',' + gr.u_subcategory + ',' + gr.u_assignment_group;
}
},
_privateFunction: function() {
}
});