
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2019 05:00 AM
Let’s say I have a table called cost center. In the cost center table I made a reference field to “department” and chose which departments own which cost centers.
On the service catalog, I have a reference variable to that table, allowing the user to select a cost center.
I have a field on the form called department, which automatically pulls the user’s department as well, So I want to show only the user’s department’s cost centers when selecting the variable in a reference qualifier. We might add a variable later that allows the user to pull a different department to filter + that user’s department.
Is this possible? If so how would I do accomplish this.
Solved! Go to Solution.
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2019 05:33 AM
Hi Andrew,
You can acheive this by Script include and reference qualifier :
This Script will list out all the Cost centres for the selected department.
Script Include Name : GetCostCentres
API Name : global.GetCostCentres
function GetCostCentres(){
var array = [];
var dept = current.variables.variable_name; //give department variable name of service catalog
// gs.addInfoMessage(dept);
var gp = new GlideRecord('cost_centre'); //glide to cost centre table
gp.addEncodedQuery('u_department='+dept); //here u_department is the field created in cost centre table
//gs.addInfoMessage(gp.getEncodedQuery());
gp.query();
while(gp.next())
{
array.push(gp.getValue("sys_id"));
}
gs.addInfoMessage(array.toString());
return 'sys_idIN' +array;
}
Reference qualifier :
javascript:global.GetCostCentres(); //add this to cost centre variable in service catalog
Regards,
Sanket

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2019 05:33 AM
Hi Andrew,
You can acheive this by Script include and reference qualifier :
This Script will list out all the Cost centres for the selected department.
Script Include Name : GetCostCentres
API Name : global.GetCostCentres
function GetCostCentres(){
var array = [];
var dept = current.variables.variable_name; //give department variable name of service catalog
// gs.addInfoMessage(dept);
var gp = new GlideRecord('cost_centre'); //glide to cost centre table
gp.addEncodedQuery('u_department='+dept); //here u_department is the field created in cost centre table
//gs.addInfoMessage(gp.getEncodedQuery());
gp.query();
while(gp.next())
{
array.push(gp.getValue("sys_id"));
}
gs.addInfoMessage(array.toString());
return 'sys_idIN' +array;
}
Reference qualifier :
javascript:global.GetCostCentres(); //add this to cost centre variable in service catalog
Regards,
Sanket

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2019 09:38 PM
Thanks! That worked

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2019 05:41 AM
Is the variable that pulls the users department a reference field? If so you should be able to do an advanced reference qualifier on your cost center variable. Should be something like below. The filed name I have at the beginning of the script below should be replaced with the filed name from the cost center table and the variable needs to be replaced with the name of the variable that holds the users department.
javascript:'u_departmentCONTAINS' + current.variables.department;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2019 06:27 AM
Hi Andrew,
you already have a variable which refers cost center table; and already you are having variable which stores user's department so you can apply following reference qualifier
use your variable name here
javascript: 'department=' + current.variables.<departmentVariable>
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader