
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2024 08:38 AM
Hi - We want to have a country field on a catalog item that, when selected, restricts the possible choices from a subsequent reference field. The problem is that we don't want to see every location from the country chosen. It's just a handful.
I have a ajax call that returns an array of sys_ids for the locations depending on the country selected. What is the best way to now use that influence the query in the locations field?
Or do I need to change the field type to choice?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2024 09:53 AM - edited 04-23-2024 09:55 AM
Hi @Andrew Bettcher ,
You should be able to use an advanced reference qualifier on the reference field to perform the filter of the list.
In your case, you would pass your form values to a script include to return the query.
For example:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2024 09:04 AM
I've added a select box field and pushed my array into it. The problem is that I've now got a drop down box containing a load of sys_ids. How do I look up the labels and use them instead? My client script is on a VDI which I can't paste out of but I'll add it below.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2024 09:06 AM
As above, this is my current client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var location = g_form.getValue('room_location');
var populateBuilding = new GlideAjax('AvMeetingPopulateLocationAjax');
populateBuilding.addParam('sysparm_name', 'populateLocation');
populateBuilding.addParam('sysparm_location', location);
populateBuilding.getXML(populateBuildingField);
}
function populateBuildingField(response) {
g_form.clearOptions('room_building2'); //clears all choices from room_building2
var answer = response.responseXML.documentElement.getAttribute('answer');
g_form.addErrorMessage(answer);
//answer = JSON.parse(answer)
var locationArray = answer.split(',');
for (var i = 0; i < locationArray.length; i++) {
g_form.addOption('room_building2', locationArray[i], locationArray[i]);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2024 09:53 AM - edited 04-23-2024 09:55 AM
Hi @Andrew Bettcher ,
You should be able to use an advanced reference qualifier on the reference field to perform the filter of the list.
In your case, you would pass your form values to a script include to return the query.
For example:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2024 04:34 AM
Thank you Jon. In the end I updated the target variable to a select box. I'll near this in mind for next time.