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-06-2025 05:04 AM
why not use advanced ref qualifier rather than using query business rule?
query business rule will impact all fields in instance which refer to this table
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 07:56 PM
Hope you are doing good.
Did my reply answer your question?
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 10:13 PM
The client proposes that in the sc_cat_item table, if a field is referencing the user group table, and the group has the attribute u_apply_to_catalog_item = false (because we are currently working on a PDI), then the filter should apply only to those records where the group is referenced in the sc_cat_item table.
Additionally, the client requires that if a group is referenced in approximately 30 catalog items, the reference qualifier should be applied to each of these catalog items. The reference qualifier should only filter records where the user group is inactive (i.e., records where the active flag is false).
Moreover, this logic should only be applicable to sc_cat_item table records, and not to any other tables such as the portfolio table.
In summary, the client requests that:
The filter should apply only to sc_cat_item records that reference the user group.
The logic should only be relevant to the sc_cat_item table, not the portfolio table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2025 10:43 PM
so what's not working in the advanced ref qualifier?
did you add logs and see?
Something like this in advanced ref qualifier on variable referring to sc_cat_item should work
var CatalogItemFilter = Class.create();
CatalogItemFilter.prototype = {
initialize: function() {},
filterCatalogItems: function() {
var arr = [];
var gr = new GlideRecord('sc_cat_item');
gr.addQuery('groupField.u_apply_to_catalog_item', false);
gr.query();
while (gr.next()) {
var userGroup = gr.groupField.getRefRecord();
if (userGroup && !userGroup.active) {
arr.push(gr.getUniqueValue());
}
}
return 'sys_idIN' + arr.toString();
},
type: 'CatalogItemFilter'
};
Ref qualifier as this
javascript: new CatalogItemFilter().filterCatalogItems();
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