Reference Qualifier for Department

Andrew112
Kilo Guru

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. 

1 ACCEPTED SOLUTION

Sanket Khabiya
Kilo Sage

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

View solution in original post

4 REPLIES 4

Sanket Khabiya
Kilo Sage

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

Thanks! That worked

Brian Lancaster
Tera Sage

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;

Ankur Bawiskar
Tera Patron
Tera Patron

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader