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-20-2025 05:52 AM
try this ensure the 1st variable has Lookup value field set to SysId
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