filter a list of records based on another variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2026 11:20 PM
i have 2 variables below in my catalog item:
variable A: building code
variable B: asset code
variable A is a lookup select box based on another variable
once variable A is selected, a list of values for asset code will be displayed based on the selected variable A , and multiple values can be selected
these 2 variables are from the same table
what is the best way to achieve this?
what i have tried:
- lookup select box for variable b but only single value can be selected
- list collector but unable to filter the values based on variable A
- variable set but the values are outside of the variableset
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2026 12:21 AM - edited 01-07-2026 12:22 AM
Heyhey,
If you only want one value to be selected, a lookup select box is probably best. For multiple selection, use a lookup multiple choice or a list collector (if you have a lot of choices). To re-filter the variable get some inspiration here: https://www.servicenow.com/community/developer-articles/creating-dependent-variables-in-service-cata...
If you want to reuse this variable combination, then yes, put it into a variable set.
Hope this helps,
Regards
Fabian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2026 12:58 AM
variable B should be list collector type for allowing multiple selection and can restrict values based on other variable using reference qualifier
Also why both variables are referring to same table?
share some screenshots
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2026 07:20 PM
any update to this?
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2026 08:28 PM
Hey @Hafila Hatta ,
Great question! You want to filter a multi-select variable based on another variable's selection. Here's the best approach:
Solution: Use a List Collector with Reference Qualifier
- Variable A (Building Code) - Keep as Lookup Select Box or Reference field
- Type: Lookup Select Box or Reference
- Reference: Your table (e.g., cmn_building)
- Variable B (Asset Code) - Set up as List Collector
- Type: List Collector
- Reference: Same table as Variable A
- Reference Qualifier: javascript:current.variables.variable_a_name
Detailed Setup for Variable B:
In the Reference Qualifier field, use:
javascript:'building_code=' + current.variables.building_codeReplace building_code with your actual field name and building_code with Variable A's name.
If they're from the same table and you need to filter by the selected record:
Reference Qualifier:
javascript:'sys_id!=' + current.variables.building_code + '^building_code=' + current.variables.building_code.building_codeAlternative: Use Client Script for Dynamic Filtering
If the reference qualifier doesn't work perfectly, add an onChange Client Script on Variable A:
function onChange(control, oldValue, newValue, isLoading) { if (isLoading || newValue == '') { return; } // Get Variable B (list collector) var assetCodeField = g_form.getReference('asset_code'); // Set reference qualifier dynamically var refQual = 'building_code=' + newValue; g_form.setReferenceQualifierForVariable('asset_code', refQual); // Clear previous selections g_form.clearValue('asset_code'); }
Pro Tips:
- Make sure Variable A comes before Variable B in the order
- Test in the Service Portal if you're using it - List Collectors work differently there
- If using Variable Sets, both variables need to be in the same set for client scripts to work properly
If List Collector still doesn't filter: Check your Table ACLs - the reference qualifier might be getting blocked by security rules. You may need to adjust read ACLs on your table.
Let me know if you need help with the exact field names or run into any issues!
Hope this helps! If this resolves your issue, please mark it as the accepted answer so others can find the solution easily.
Best regards!
Sandesh
