Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Adding a Dependent Variables using Question_Choice

dbl
Mega Explorer

I need to make choice list B dependent on the selection of choice list A selection within a Catalog Item. Each variable is a short list of values (not currently a reference to an existing table).

I reviewed this WIKI article:
http://wiki.service-now.com/index.php?title=Adding_Dependent_Variables
(and other WIKI articles) and made it work by creating a custom table then making choice2 dependent on choice1, and added entries into sys_choices table.

Is there a better way to do this leveraging a variable's question_choice table?

3 REPLIES 3

Jace Benson
Giga Sage

Another way to do this could be to just fill in the list manually with javascript; below is an example of how to do that.



function onChange(control, oldValue, newValue, isLoading) {
if (oldValue == newValue){
//if the value hasn't changed do nothing
return;
}
if (newValue == "OpTime"){
g_form.getControl('type_of_request').options.length = 1;//remove all options except --none--
g_form.addOption('type_of_request', "Documentation", "Documentation");
g_form.addOption('type_of_request', "Surgeon Authorizations", "Surgeon Authorizations");
}else if (newValue == "HB"){//hb
g_form.getControl('type_of_request').options.length = 1;//remove all options except --none--
g_form.addOption('type_of_request', "HB Something", "HB Something");
g_form.addOption('type_of_request', "Billing Stuff", "Billing Stuff");
}else if (newValue == "" || newValue == undefined || newValue == "undefined"){
//if --none-- is picked clear options as well.
g_form.getControl('type_of_request').options.length = 1;//remove all options except --none--
}


Or if the second dropdown data is in another table you could query that and return that into the list.


There is another way to do this which is way better.   When I replied years ago I don't know if it existed, but it does now.



Attribute ref_qual_elements



https://docs.servicenow.com/bundle/istanbul-it-service-management/page/product/service-catalog-manag...



I'm pulling an example up and I'll more comments to this with that detail in a minute.


this is a simple example but you could point it to any table Capture04042017001.PNG


Then you just need to set the field 'atttributes' to have `ref_qual_elements=query` where query is the variable its dependent on.   This just triggers an update when query changes.