Show/Hide choices of field based on selection of another field choice on portal form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2022 08:45 AM
Hi Developers,
I need one client script for below requirement.
1. On Portal If we select "Category" -- "Strategic" -- > it should populates "Type" values are "Project" and "Enhancement".
2. On Portal If we select "Category" -- "operational" -- > it should populates "Type" values are "Change" and "Defect".
please help me with complete Catalog Client script.
Thanks in Advance.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2022 09:06 AM
This can and should be done using reference qualifier. Of course the lookup version of the select box should be used as variable type.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2022 09:09 AM
If these are being mapped to a "category" and "type" field (based on the values you're presenting, it looks like you might be creating a demand with this record producer), you can follow these articles:
ServiceNow Record Producer Variable Dependent Variable | Concurrency - Concurrency
Using Category and Subcategory on record producers | Pathways Consulting Group (pathwayscg.com)
If not, or you need something more complex, I've had success with this in the past:

-
Write a script include function that takes a parameter (which will be the first variable's value) to query the reference table of the second variable, and return a stringified encoded query based on that query.
-
We need to tell the system that the first variable has a dependency on it. To do this, in the "Default Value" tab (at least this is usually where it is), we need to add the following to the "Variable attributes" field:
-
For the second variable, we also need to tell the system that this variable is dependent on the first. Following the same navigation as the previous step, add the following to the "Variable attributes" field:
-
Finally, in the "Type Specifications" tab (again, this is usually where this field is), we need to add the following to the "Reference qual" field:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2022 09:12 AM
Hi,
Please use below logic in OnChange client script which should run on Change of Categor.
if(newValue=='strategic'){
g_form.clearOptions('type');
g_form.addOption('type','project');
g_form.addOption('type','enhancement');
}else if(newValue=='operational'){
g_form.clearOptions('type');
g_form.addOption('type','change');
g_form.addOption('type','defect');
}
Note: Please use variable values and choice values as per your configuration.
Thanks,
Anil Lande
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2022 09:33 AM
Hello,
If you have created the choices please use the below onchange catalog client on category field.
var cat=g_form.getValue('category');
if(cat=='strategic')
{
g_form.removeOption('type','change');
g_form.removeOption('type','defect');
}
else if(cat=='operational')
{
g_form.removeOption('type','project');
g_form.removeOption('type','enhancement');
}
Please mark answer correct/helpful based on Impact.