- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2025 04:28 AM - edited ‎03-28-2025 04:32 AM
Hi all,
I am looking for some support in order to correctly filter a Catalog Item's variables via a Cat Client Script. For example, if I select Production as a value in the Environment variable, I only want Production values to show within the Application Services variable.
The Environment variable is a Multi Choice field, with two values 'Production' and 'Non Production'.
The Application Service variable is a Reference field on the 'cmdb_ci_auto' table, which pulls in various Application Services, they also have values in this table to show whether they are 'Production' or 'Non Production'.
I am having challenges with correct syntax usage and whether I need to glide to the Application Service table. Can someone point me in the right direction please?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2025 04:59 AM
To filter the list of possible selections in a reference variable, use a reference qualifier on the Application Services variable, not a Catalog Client Script. To incorporate the value of another variable, it would look something like this:
Where 'used_for' is the name of the field on the referenced table that contains the 'Production' or 'Non Production' value, and 'v_environment' is the name of the Catalog Item variable where that value (which must match exactly) was selected.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2025 04:47 AM
You can write Onchange client script and script include, below is sample example you can modify it for you.
Client script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
// Convert the selected values into an array
var selectedValues = newValue.split(',');
// Call GlideAjax to fetch valid Application Services
var ga = new GlideAjax('FilterApplicationServices');
ga.addParam('sysparm_name', 'getFilteredServices');
ga.addParam('sysparm_env', selectedValues.join(',')); // Pass selected environments
ga.getXMLAnswer(function(response) {
if (response) {
g_form.setValue('application_service', response); // Set filtered value
}
});
}
Script inlcude:
getFilteredServices: function() {
var envs = this.getParameter('sysparm_env'); // Get selected environments
var envList = envs.split(','); // Convert to array
var gr = new GlideRecord('cmdb_ci_auto'); // Application Services table
gr.addQuery('u_environment', 'IN', envList); // Filter based on selected Environment
gr.query();
var serviceIds = [];
while (gr.next()) {
serviceIds.push(gr.sys_id.toString());
}
return serviceIds.join(','); // Return filtered sys_ids
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2025 04:59 AM
To filter the list of possible selections in a reference variable, use a reference qualifier on the Application Services variable, not a Catalog Client Script. To incorporate the value of another variable, it would look something like this:
Where 'used_for' is the name of the field on the referenced table that contains the 'Production' or 'Non Production' value, and 'v_environment' is the name of the Catalog Item variable where that value (which must match exactly) was selected.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2025 05:37 AM
Hi Brad,
Thanks for the response. This is what I have configured as per your guidance, but the filtering isn't working currently -
Ref Qual:
Environment field:
Cat Item Variable:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2025 05:40 AM - edited ‎03-28-2025 05:41 AM
You have an errant quote after environment.