Using a Lookup Select Box to Narrow options for Second Lookup Select Box

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2025 03:23 PM - edited ‎05-20-2025 05:44 AM
Hello, Developers!
Here's the low down:
- I have two lookup select box variables on my catalog item that I want to filter the same table
- The first one should filter based on a field we're using as a flag called "type" and it should equal to "category"
- The second field should filter the same table with the "type" equal to "topic" AND it should show records from the table that have a "parent" field (reference field for the same table with "name" field as display value) set to the same option selected from the first list select box
Here's what I've tried:
- An advanced Reference Qualifier
- javascript:'parent='+ current.variables.category
- javascript:'parent='+ current.variables.category.toString()
- I tried a script include
- Code:
var CategoryReferenceQualifier = Class.create();
CategoryReferenceQualifier.prototype = {
initialize: function() {},
getSysIdFromName: function(name) {
try{
var categorySysId = '';
var gr = new GlideRecord('my_custom_table_name');
gr.addQuery('category_name', name);
gr.query();
if (gr.next()) {
categorySysId = gr.sys_id.toString();
}
return categorySysId;
}
catch (ex) {
gs.error("Error in getSysIdFromName: " + ex);
return '';
}
},
getReferenceQualifier: function(type, categoryName) {
var categorySysId = this.getSysIdFromName(categoryName);
if (!categorySysId) {
return '';
}
gs.info("Here's the sysID: " + categorySysId);
gs.info("Here's the type: " + type);
return 'parent=' + categorySysId + '^type=' + type;
},
type: 'CategoryReferenceQualifier'
};
- Reference Qualifier: javascript: new CategoryReferenceQualifier().getReferenceQualifier(current.Variables.category)
N.B. I used the .toString() method and the script include just in case the the "parent" reference field I'm trying to filter by needed a sysId as a string. I'm not even sure what the first list selector box data/value would look like. Is there even a way to debug reference qualifiers? I've looked at product documentation and nothing seems to be doing the trick. Please help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2025 10:15 PM - edited ‎05-19-2025 10:21 PM
Hi for your requirement, If the category variable type is reference, I think there is no need for script include.You can directly provide below code in advanced qualifier
javascript:'parent='+ current.variables.category
This will fetch all the records with parent as selected category. If you want to add additional quary on type, please use below code
javascript:"parent="+ current.variables.category+"^type=topic"
If you have to call script include use below syntax
javascript: new CategoryReferenceQualifier().getReferenceQualifier(current.Variables.category)
Thanks, and Regards
Mahesh
Please mark this response as correct or helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2025 05:45 AM
I was tryin to keep it as a lookup select box.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2025 10:33 PM
in the 2nd one add this
javascript:'parent='+ current.variables.category.toString() + '^type=topic';
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2025 05:43 AM
I tried that already. It doesn't work.