- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on ‎12-15-2019 06:24 AM
Hi All,
Unfortunately, catalog variables do not have a dependency like a field we have on the forms.
The dependent variables can be created in the service catalog in two ways:
A. Using Client Script: Onchange of Category field write following script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '')
{
g_form.clearOptions('subcategory');
g_form.addOption('subcategory', '', '-- None --');
return;
}
if(newValue =='Category 1')
{
g_form.clearOptions('subcategory');
g_form.addOption('subcategory', '', '-- None --');
g_form.addOption('subcategory','Subcategory11','Subcategory11');
g_form.addOption('subcategory','Subcategory12','Subcategory12');
g_form.addOption('subcategory','Subcategory13','Subcategory13');
}
else if(newValue =='Category 2')
{
g_form.clearOptions('subcategory');
//g_form.addOption('subcategory', '', '-- None --');
g_form.addOption('subcategory','Subcategory21','Subcategory21');
g_form.addOption('subcategory','Subcategory22','Subcategory22');
g_form.addOption('subcategory','Subcategory23','Subcategory23');
}
else if(newValue =='Category 3')
{
g_form.clearOptions('subcategory');
g_form.addOption('subcategory', '', '-- None --');
g_form.addOption('subcategory','Subcategory31','Subcategory31');
g_form.addOption('subcategory','Subcategory32','Subcategory32');
g_form.addOption('subcategory','Subcategory33','Subcategory33');
}
}
B. By Creating the table:
The client script cannot be used when we have a large number of categories and subcategories. So in such a case, we have to follow the 2nd way i.e create a table. Following are the steps you need to follow:
Now consider bank name as category and Bank choice as subcategory.
STEPS:
1. Create a custom table that contains the values of the category and subcategory. This will act as a dependency table.
2. Create Category - type of variable->Select box , and add all the required choices
3. Create Subcategory - type of variable->Lookup select box
4. Add Reference Qualifier and Variable attributes as shown in the above image.
Hit like if this post helps you.
Regards,
Snehal Madakatti
- 34,256 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Slight Correction:
For the below highlighted field - "Lookup Value field", instead of setting it as Bank Name, set it as Bank Choice.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thank you. This was very helpful.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Most Welcome! 🙂
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
How to create this table?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Most Welcome!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi,
How to create a dependency table. Can someone reply, please?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
and why we mentioned Subcategory11 twice here.
g_form.addOption('subcategory','Subcategory11','Subcategory11');
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Coz my display value and backend values have same name.
Refer here for more details -- Servicenow WIKI
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Its just like creating normal table in servicenow.
Reference - Steps for creating Table
Regards,
Snehal
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Very Useful Article. Great Job...
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
This is Very Useful.
great job..
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thank You so much and glad it was helpful!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Very Helpful Article..
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Glad that it was helpful for you.
Regards,
Snehal

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I'd advise caution around creating a new table, as this may have license implications. It may count towards your bundled table limit, depending on your licensing agreement.
The safe bet is to extend sys_choice, which is not counted as a custom table.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thanks Paul for the advise.
Regards,
Snehal
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Snehal,
This was super helpful!
I have a follow-up question:
Can you make a subcategory dependent on 2 parent varibles instead of just 1?
I have an equipment catalog item.
I created a table with 3 columns: Purpose, Make, Model
I'd like the user to choose "Purpose".
Then the "Make" list should be filtered down. (I've done this part already)
I'd like the "Model" choices to be filtered based on Purpose+Make.
Can you do this?
Joe
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Joe,
Glad that this helped you.
I tried for Model which you had mentioned, but w was not able to get the choices as expected. Not sure if we can implement -->"Model" choices to be filtered based on Purpose+Make.
If you find the solution please do let me know as well.
Regards,
Snehal M

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Why not just point your lookup select box to sys_choice and create a reference qualifier that takes into account the table name, inactive is false, and dependent value of the first lookup select box? If you're already taking advantage of the dependent value on the form (non service catalog) then you should be able to re-use that logic without creating scripts or new tables.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Good points, Ashley. Although, as Paul said above, I believe the best and simplest way is to extend the sys_choice table as that does not have any licensing implications and can be extended up to 1000 times before it does. In my experience, this is much cleaner and more reliable than simply pointing the variable to the sys_choice table.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
How does one go about extending the Sys_choice table exactly?

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
- Make the sys_choice table extendable via the table record
- Create a new table that extends sys_choice
- Make the 'Field' dictionary entry non-mandatory
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Ashely,
I think you have figured out the right approach for me, but I still struggling.
A couple of questions:
1. How do I extend the user table value "Division" to dynamically populate the "Dependent Value" column in the Choice list and also the values of some selected elements from the user table?
(Ideally I'd like to dynamically populate the values for elements: Department, Title and Location found in the User table all under the Dependent value of "Division".)
2. Why doesn't my reference qualifier pull in my variable from the form?
javascript:"dependent_value="+current.variables.division
("Division" is a value I pull from the user table in a lookup select box on the form.)
Here's a screenshot of some values I manually entered into the Choice Lists.
If I use javascript:"dependent_value="+"Corporate"
everything works.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
To dynamically populate variables based upon selection you would either have to use GlideAjax to retrieve the values with a Catalog Client Script.
The current.variables.division method should work, but you'll want to make sure you're narrowing down your search, that may be the issue, try something like:
javascript:'name=sys_user^inactive=false^dependent_value=' + current.variables.division
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
1. I would like the Choice table to automatically populate values, elements and labels for the Dependent value "Division" any time a new user is added to the sys_user table.
I don't know how to do this.
(I manually added these values to the choice table in the screenshot above to test my form.)
2. No matter what I do, the method "current.variables.divsion" doesn't show me the correct values from the choice table.
I've tried:
javascript: 'name^sys_user^inactive=false^dependent_value=' + current.variables.divison
javascript: 'dependent_value=" + current.variables.division
As a test, I manually just typed in the dependent value as a string and then the pulldown in my form worked.
javascript:"dependent_value="+"Corporate"
What could be going on?

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I see your example is javascript: 'name^sys_user^inactive=false^dependent_value=' + current.variables.divison
The Caret symbol denotes adding another field and not an operator for it's value, did you try:
javascript:'name=sys_user^inactive=false^dependent_value=' + current.variables.division
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
So this is what my variable looks like now (see below).
My pulldown shows all of the labels of anything in the choice table with a blank "Dependent_value".
So clearly, I'm not gettting the "Divsion" display value I need.
As an experiment I did this in a UI Script:
alert('Current Division is: ' + g_form.getValue('division'));
alert('Current Display Division is: ' + g_form.getDisplayValue('division'));
The first value was the sys_id of division.
The second value was the string "Corporate".
I then updated my Choice table as shown.
Still no luck pulling "division" from the form to use as a reference qualifier.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Paul,
I tried your recommendation of extending sys_choice and was able to do so, however what do we do after we extend the table. Surely there's more to this as I now have the extended table to choose from but the choice fields available aren't fields that I would use for a Category and Subcategory. I therefore added Category and Subcategory fields (each with their own Dictionary Entries and dependencies) however, the dependency drop down doesn't work.
Thanks,
AJ

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
You need to add a reference qualifier that references the extended choice table, including the dependent field in the query, making sure it is the same value as your dependent variable.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I suppose it depends on if you're referencing an existing choice list on a table, versus the ability to extend sys_choice and create new choices for your functionality. For example, working with the Incident table may not be as forgiving as one may be referencing choices created long ago. My scenario is that the choices already exist, and one can reference sys_choice instead of extending or scripting. But the ability to extend sys_choice is great and I've used it already in scoped applications to provide functionality without impacting licensing.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Ah, I did not know Division was returning a sys_id and not a value that would correlate to the value on your sys_choice.
Can you provide more information on what you're trying to do on a high level? I think the comments are floating between different ways to accomplish what Paul had originally posted about, and now a more specific requirement that is dealing with reference fields, dependent values, and populating values from reference fields, in which I and others were providing answers on the basic functionality and original post itself.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I don't have the "Reference Qualifier" option. See screenshot below. I've elevated my Admin Role and no luck. What

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Set 'Choice table' as your extended choice, and 'Choice field' as the display value (i.e. value).
If you want dependencies, you have to use a variable that supports References, then create a reference qualifier to handle your dependency. These include:
- Lookup Multiple Choice
- Lookup Select Box
- List Collector
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thanks Paul, that helped in regards to the Reference Qualifier. However, I'm still not able to accomplish the overall goal of dependencies through extending the Choice Table. I was able to do it through creating a completely new table, but as you originally mentioned I'd prefer to extend rather than create a new table to avoid license implications. Is there anyway you can provide screenshot instructions on how to accomplish dependencies by extending the choice table similar to what Snehal did in his original post?
Thanks,
AJ

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
The dependency is created via the reference qualifier, using the dependent value field on the extended table.
Example of category/subcategory below, for the subcategory variable
javascript:'dependent_value=' + current.variables.category + '^ORdependent_value=^u_choice_set=subcategory^inactive=false^EQ';
u_choice_set is a field i use to reference the variable name so i can use the extended table for multiple variables
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I appreciate your assistance Paul, but I'm still not able to achieve dependent fields. I've followed your latest recommendation of using the preexisting Dependent Value field from my extended choice table with the script you've provided and no luck.
There may be other factors that are different between the processes of creating a new table and extending the Choice table to achieve dependent fields that I'm not aware of being the newbie that I am.
Thanks,
AJ

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Can you provide your table specification and reference qualifier code?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Paul,
See below Table specs and the Subcategory variable specs/ref qualifier code. I tried with and without the u_choice_set part of the qualifier code.
Thanks,
AJ

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Lookup value field should be 'value' and lookup label fields should be 'label' (assuming you are leveraging the existing choice fields - not sure why you wouldn't do this)
See screenshot below, continuing from my example:
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thanks Paul for your prompt response. I think that's the problem: I'm not using the existing Choice fields since I don't know which fields to use and how to use them which is why I asked if you could you could provide screenshot instructions on how to accomplish dependencies by extending the choice table similar to what Snehal did in his original post. I assumed the benefit, in this situation, of extending an existing table was to bypass the licensing implications. I'm sorry I forgot to mention that I'm new to ServiceNow.
BTW, I understand you're not able to provide further assistance as no one in the Community is obligated to do so.
Thanks again for your help!
AJ

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
If you need further assistance, I would suggest raising a question that addresses this specifically. You'll be much more likely to get help doing that.
Hope you've had success.
Regards,
Paul
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Snehal,
I tried 1st method, A. Using Client Script:
but it is not working. I made catalog client script. Here it is:-
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if(newValue =='rhel')
{
g_form.clearOptions('os_version');
g_form.addOption('os_version','w1','Windows 2019');
g_form.addOption('os_version','w2','Windows 2016');
g_form.addOption('os_version','w3','Windows 2012 R2');
g_form.addOption('os_version','w4','Windows 2008 R2');
}
else if(newValue =='suse')
{
g_form.clearOptions('os_version');
//g_form.addOption('subcategory', '', '-- None --');
g_form.addOption('os_version','r1','RHEL8');
g_form.addOption('os_version','r2','RHEL7');
g_form.addOption('os_version','r3','Redhat Linux 7.4');
g_form.addOption('os_version','r4','Redhat Linux 6.9');
}
else if(newValue =='windows')
{
g_form.clearOptions('os_version');
//g_form.addOption('subcategory', '', '-- None --');
g_form.addOption('os_version','s1','Oracle Linux 6.7');
g_form.addOption('os_version','s2','Oracle Linux 6.4');
g_form.addOption('os_version','s3','Oracle Linux 5');
}
}
It is not working. can anybody help on this.?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Snehal,
This is a great article but how would i create multiple dependencies e.g variable A, Variable B (dependant on Variable A), Variable C (dependant on Variable B) and Variable D (dependant on Variable C)
Would i just mimic step 3/4?
Kind regards
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
V,
Look at Ashley and Joe's comments above. They used sys_choice for these types of things and it's purposefully built for this type of thing. Once you have your variable options in sys_choice, use a reference or lookup select box and reference qualifier to filter for your options. Repeat for each variable. Super simple once you get your head wrapped around using the sys_choice table to hold all your options.
The key is your reference qualifier. A well defined reference qualifier query works on any table and almost any field.
Note: sys_choice is no longer an exempt table, but a great alternative is lookup tables if you need free (under 1000) access to a custom table for this purpose. But in most cases, sys_choice should be able to handle whatever you throw at it.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Much simpler
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
This onChange script dynamically pulls the dependent values from the sys_choice table. In my case had a reference field as a parent for a choice field. The choice didn't update unless a commit happened. This allows it to work without needing to save after the selection.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
// clear values on change
g_form.clearOptions('category');
// set input variable
var s = g_form.getDisplayBox('business_service').value;
// query for category values
var gr = new GlideRecord('sys_choice');
gr.addQuery('table', 'change_request');
gr.addQuery('element', 'category');
gr.addQuery('dependent_value', s);
gr.addQuery('inactive', false);
gr.query();
g_form.addOption('category', '' , '-- None --', 0);
while (gr.next()) {
// add code here to process the incident record
var v = gr.value;
var l = gr.label;
g_form.addOption('category', v, l); //, 1);
}
}
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hello everyone,
I have the similar requirement, but based on the multiple selection, the other variable options should be available.
So, I have created my first variable as List collector and the second variable as lookup select box(referencing to custom table). Now, I'm struck to get the variables on my second variable based on the first variable.
We have script include created for it. but, something is wrong with the code. Can anybody please help me to solve this issue.
Also, for the second variable, I have provided reference qualifier as below - (javascript:getProductForWorkpackage.getProductWorkpackageList(current.variables.select_lines_of_services_that_will_be_provided_under_this_project));)
Please find the below code for the script include,