- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-16-2020 06:45 AM
Hi,
I am trying to set a dependency on a Variable Set field called Cost Center so it only shows the list of Cost Centers that are available to the requester which matches their Country set against their user profile when they raise a request in the Service Catalog.
We have currently used this option for a specific field on the Incident and also for what items they can see in the User Catalog but we now want to extend that to include the cost center as well. We currently have a high number of cost centers set up so being able to only show the ones valid for the requesters country would be beneficial to the raising of requests.
I have seen a number of other posts about setting dependencies on variable fields in the catalog but none seem to match exactly what I am trying to do.
The current configuration we have is to add a Country field as a reference to the sys_user table and the same field to the user_criteria table but this one is a List. Both these new columns are reference to the core_country table.
Next, in the dictionary for the required incident field, we added a dependent on the Caller User Country field and added in the sys_id to all the choices we need to make dependent.
This then allowed us to have a field on the incident form that is dependent on the User Country selected on their profile.
For the service catalog, we added a user criteria option for the country ie UK only was set to country of United Kingdom and then under the maintain items for the service catalog, we added a "available for" or "not available for" option to each item for this then to only show where it matched the Users Country.
Both of these options work and allow us to have a dependency field and user catalog items only available for certain countrys.
Leading on from this, we now want the Cost Center to only show if the cost center matches the Users Country so we can reduce the list of cost centers they currently see. The difference with Cost Center is it is part of a variable set and not on a standard form as I understand it
Any help would be grately appreciated.
Thanks
Alex
Solved! Go to Solution.
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-16-2020 09:25 AM
Hi
I just sat down and created an example for you, which hopefully will solve your issue:
The solution takes the following steps:
- The current user will have a "Location" configures in his "sys_user" record.
- This "Location" record (cmn_location) does have a "country" field,
which will define the country relevant for searching Cost Centers.
- I will search for all Records in the Cost Center table, where the "Country" in the
referenced "Location" field is the same as in the user record.
The solution is set up for a Catalog Variable of type "Reference" to the "Cost Center" table.
The Reference Field uses an advanced "Reference Qualifier" to limit the shown records.
(I hope this meets your requirements, as I have understood it from your question above).
Steps to reproduce:
1) Create a Script Include to be used in the Advanced Reference Qualifier later (in your Catalog Variable)
Note: The "Name" field MUST be the same as the name in the Script !!
Here is the Script for copy/paste:
var DirkCountryCostCenterRefQual = Class.create();
DirkCountryCostCenterRefQual.prototype = {
initialize: function() {
},
getData: function(current) {
var mylocation = gs.getUser().getRecord().getValue('location');
var gr = new GlideRecord('cmn_location');
gr.addQuery('sys_id', mylocation);
gr.query();
var myCountry = '';
if (gr.next()) {
// gs.info(gr.getDisplayValue('country'));
myCountry = gr.getValue('country');
}
return "location.country=" + myCountry;
},
type: 'DirkCountryCostCenterRefQual'
};
2) Create a Test-Catalog Item
The Catalog Item (1) will need a Catalog Variable (2) which I called "cost_center" (3) - see details in the screenshot below.
Set the Variable (1) to "Type" = "Reference" and enter the Question (3).
On the "Type Specifications" Tab, set the "Reference" field to the "Cost Center" (cmn_cost_center) table.
Set the "Use reference qualifier" field to "Advanced" (3).
Enter the Value shown in the "Reference qualifier" (4) field as shown in the screenshot below. This will use the Script Include created above to create the filter for the Lookup list.
Copy it from here:
javascript:new DirkCountryCostCenterRefQual().getData(current)
4) Create Test records
The User is configured like shown below:
The used Location is set up like:
You can see, that the "Country" field is set up as "Mexico" (1).
The following marked three Cost Centers are using Locations, where the Country is set to "Mexico". These will be the Cost Centers shown in the reference List (Catalog Variable) below:
5) Finally earn your fruits
Test your catalog Item and open the reference List:
It will show only the matching and desired records.
I hope, this will meet your requirement to make you happy.
Just give it a shot and let me know, please.
Let me know if that answers your question and mark my answer as correct and helpful.
BR
Dirk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-18-2021 11:32 AM
Hi Dirk,
I am trying to amend the script to work off the users country field that is set against their profile and not the country of their location as we currently have. The country field is called "u_user_country" and I can get the script to run as expected but it doesnt work. Are you able to have a quick look and see if I have something wrong on the script.
var CountryCostCenterRefQual = Class.create();
CountryCostCenterRefQual.prototype = {
initialize: function() {
},
getData: function(current) {
var myusercountry = gs.getUser().getRecord().getValue('u_user_country');
var gr = new GlideRecord('core_country');
gr.addQuery('sys_id', myusercountry);
gr.query();
var myCountry = '';
if (gr.next()) {
// gs.info(gr.getDisplayValue('country'));
myCountry = gr.getValue('name');
}
return "country.name=" + myCountry;
},
type: 'CountryCostCenterRefQual'
};
Everything seems to be changed compared to the original script you helped me with but like I say, this doesnt then filter the cost centres on their country field now.
I have set up a reference field on Cost Centre table pointing to the core_country field as we were doing with the location field already there
Any help is greatly appreciated
Thanks
Alex