Select Box choices dependant on another Select Box
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2017 12:47 PM
Can I do this without creating a new table?
I have two variable select boxes.
The first one has choices A, B and C.
My second select box has choices, but they are dependant on what is selected on Select Box one.
Someone suggested that I add my choices to variable Select Box one (like normal), and then with Select Box two, choose the sys_choice table for "Choice Table" and Value for "Choice Field."
Then go to they sys_choice table and add:
Table: sc_req_item
Element: (my select box one field)
Lable: the label of one of my select box two choices
Value: the value of one of my select box two choices
depends on: the choice of on of the select box one choice.
and keep adding for each select box 2 choice.
Unfortunately this is not working. Am I missing something? Or is the only way to do this is with a table and a client script?
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2017 02:45 PM
These are choices that are already in a table. But this helps in the future! And this if for a Service Catalog Item as well.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2017 02:56 PM
You can use onChange catalog client script. Script looks like this (assumes variables are named category and subcategory):
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
if(newValue == oldValue){
return;
}
//remove all items from subcat drop down to start
// Used the g_form.clearOptions() function instead of g_form.removeOption() function
g_form.clearOptions('subcategory');
g_form.addOption('subcategory', '', '-- None --', '0');
var ga = new GlideAjax("CatalogAjax");
ga.addParam("sysparm_name", "getSubcategories");
ga.addParam("sysparm_cat", newValue);
ga.getXML(ajaxResponse);
function ajaxResponse(serverResponse) {
var result = serverResponse.responseXML.getElementsByTagName("result");
var subcat = serverResponse.responseXML.getElementsByTagName("subcat");
for(var i = 0; i < subcat.length; i++) {
var name = subcat[i].getAttribute("name");
var value = subcat[i].getAttribute("value");
var sequence = subcat[i].getAttribute("sequence");
g_form.addOption('subcategory', value, name, sequence);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2023 07:25 AM
this video is not suitable for catalog items
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2018 06:12 AM
Hi Kemmy,
I had resolve this issue for my one of the requirements. I had created two 'Select Box' type variable where second variable (Model Types) was depend on the selection on first variable (Laptop manufacturer).
I used catalog client script in order to achieve it.
I believe it will be serve your purpose. Please mark answer correct and helpful based on the response.
Regards,
Nikhil Dixit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2018 10:20 AM
This is an older post but I tried this, added in the onChange script and my field is blank, it's not putting any of the values in the drop down.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == ''){
return;
}
var getSd = g_form.getValue('variables.edge_model');
if(getSd == "5x0"){
g_form.clearOptions('variables.site_tier');
g_form.addOptions('variables.site_tier', 'tier_1', 'Tier 1');
g_form.addOptions('variables.site_tier', 'm_a', 'M&A');
}else if(getSd == "840"){
g_form.clearOptions('variables.site_tier');
g_form.addOptions('variables.site_tier', 'tier_1', 'Tier 1');
g_form.addOptions('variables.site_tier', 'tier_2', 'Tier 2');
g_form.addOptions('variables.site_tier', 'tier_3', 'Tier 3');
g_form.addOptions('variables.site_tier', 'data_center', 'Data Center');
g_form.addOptions('variables.site_tier', 'm_a', 'M&A');
}else if(getSd == "1000"){
g_form.clearOptions('variables.site_tier');
g_form.addOptions('variables.site_tier', 'tier_1', 'Tier 1');
g_form.addOptions('variables.site_tier', 'tier_2', 'Tier 2');
g_form.addOptions('variables.site_tier', 'tier_3', 'Tier 3');
g_form.addOptions('variables.site_tier', 'data_center', 'Data Center');
g_form.addOptions('variables.site_tier', 'm_a', 'M&A');
}else if(getSd == "2000"){
g_form.clearOptions('variables.site_tier');
g_form.addOptions('variables.site_tier', 'tier_1', 'Tier 1');
g_form.addOptions('variables.site_tier', 'tier_2', 'Tier 2');
g_form.addOptions('variables.site_tier', 'tier_3', 'Tier 3');
g_form.addOptions('variables.site_tier', 'data_center', 'Data Center');
g_form.addOptions('variables.site_tier', 'm_a', 'M&A');
}else if(getSd == "Virtual"){
g_form.clearOptions('variables.site_tier');
g_form.addOptions('variables.site_tier', 'tier_1', 'Tier 1');
g_form.addOptions('variables.site_tier', 'tier_2', 'Tier 2');
g_form.addOptions('variables.site_tier', 'tier_3', 'Tier 3');
g_form.addOptions('variables.site_tier', 'data_center', 'Data Center');
g_form.addOptions('variables.site_tier', 'm_a', 'M&A');
}else {
g_form.clearOptions('variables.site_tier');
}
}