Hi Community, Request for Assistance in Dynamically Adding Reference Qualifier via Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2025 08:14 PM
We are attempting to implement a Before Query Business Rule on the Portfolio table that filters out records based on their association with Service Catalog Items (sc_cat_item). Specifically, when the “Apply to Catalog Item” field is set to true, we want to ensure that any Portfolio referenced in Catalog Items is automatically excluded from query results—but only when the query originates from the sc_cat_item table.
The goal is to dynamically add a filter to hide these Portfolios during selection in Catalog Items, while ensuring that this rule does not impact queries from other tables. (Note: instead of using reference qualifier we need some automation process here)
We are currently using a script and a system property to retrieve the calling table name and construct the query accordingly. However, we are encountering challenges ensuring that the filtering applies only to the sc_cat_item context, without affecting other tables.
Could you please assist us in refining the approach or suggest a solution that meets the above requirement?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2025 04:44 AM
Thank you for marking my response as helpful.
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
04-06-2025 11:08 PM
Somewhat similar implementation: get use of sc_cat_item_group_mtom table to store catalog items.
- Navigate to the Service Catalog Item [sc_cat_item] table User Group reference field & Add this script to the "Reference qual" field in the Dictionary entry
- Provides different filtering logic for new vs. existing catalog items for an example
- For existing items, it includes:
- Groups with catalog management roles
- Groups explicitly permitted for this catalog item (via a many-to-many sc_cat_item_group_mtom table)
- Groups associated with the catalog item's category
- For new items, it shows active groups by default
You can customize the qualifier logic based on your specific business requirements.
// Advanced reference qualifier for the sys_user_group reference field on sc_cat_item table
function refQualifier() {
// Get the current catalog item's sys_id
var catalogItemId = current.sys_id;
// Initialize the qualifier string - will be expanded based on conditions
var qualifier = '';
// If this is a new catalog item being created
if (catalogItemId == '' || !catalogItemId) {
// For new items, we'll use a basic condition to show active groups
qualifier = 'active=true';
} else {
// For existing items, build a more complex qualifier
// First, get any groups that have specific permissions for this catalog item
var permissionsGr = new GlideRecord('sc_cat_item_group_mtom');
permissionsGr.addQuery('sc_cat_item', catalogItemId);
permissionsGr.query();
var permittedGroups = [];
while (permissionsGr.next()) {
permittedGroups.push(permissionsGr.getValue('group'));
}
// Include groups that have catalog management roles
qualifier = 'active=true^role=catalog_manager';
// If we found any explicitly permitted groups, include those as well
if (permittedGroups.length > 0) {
qualifier += '^ORsys_idIN' + permittedGroups.join(',');
}
// If the catalog item has a specific category, we might want to limit to groups associated with that category
if (current.category) {
var categoryId = current.getValue('category');
qualifier += '^ORcategory=' + categoryId;
}
}
return qualifier;
}
Hope this helps 🙂