Dictionary Override: Custom Script Include Blocked by Existing Reference Qualifier
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
Subject: Dictionary Override – Reference Qualifier blocking custom Script Include logic for filtering Department field.
Hi all,
I’m working on a use case in ServiceNow involving the cmdb_ci_business_app table.
In this table, there are two reference fields:
Business Unit: references the Business Unit table.
Department: references the Department table.
In the Department table, there’s also a Business Unit reference field.
The requirement is:
When a user selects a Business Unit in the cmdb_ci_business_app form, the Department field should display only those departments that are associated with that selected Business Unit.
I’ve created a Dictionary Override for the Business unit field (specific to the cmdb_ci_business_app table) and checked the Override reference qualifier option.
My custom reference qualifier script is:
javascript: new getbuSubdivision().showbuSubdivs(current.getValue('business_unit'));
Now, i wrote Script include, so that i can apply a restriction on department field in business app table:
Script Include:
var getbuSubdivision = Class.create();
getbuSubdivision.prototype = {
showbuSubdivs: function(bUnit) {
//gs.info("Mihir Testing");
var subDivisions = [];
var gr = new GlideRecord('cmn_department');
gr.addEncodedQuery('parent=NULL^code=APMSUBBU^business_unit='+bUnit);
gr.query();
while (gr.next()) {
subDivisions.push(gr.getValue('name'));
}
return 'sys_idIN' + subDivisions.toString();
},
initialize: function() {
},
type: 'getbuSubdivision'
};
but as a Dictionary Override on the Business Unit field of cmdb_ci_business_app.
Then suddenly your Business Unit field itself stopped showing records.
i can’t see any business unit records in business unit field. i unable to select any of the records from business unit field.
Let us understand with attached snaps: what is the exact requirement:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
Hi,
You don't need to use a script include for this. Instead, return an encoded query which will avoid needing to perform multiple database look ups. The following is a working example of a reference qualifier in a dictionary override and provided OOTB on the field
javascript: current.business_unit ? 'business_unit=' + current.business_unit : ''
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
Hi @mihirgupta,
Could you clarify why you're applying the reference qualifier on the Business Unit field? If you're looking to filter by department, the reference qualifier should actually be applied to the Department field.
Additionally, there's already an out-of-the-box (OOTB) Dictionary Override on the cmdb_ci_business_app table's Department field, which is handling the same functionality.
Dictionary Override Link:
If my response helped, please mark it as the accepted solution so others can benefit as well.
