Catalog item variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2025 03:05 AM
Hi All,
In my catalog item I have a reference variable. When user clicks on this variable it should show those records only where the 3rd word of the name contains bdrr.
Can you please help me out.
Thanks in advance.
Regards,
Abhisek Chattaraj.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2025 03:19 AM
An advanced reference qualifier calling a script include that uses regex to check on the content of the name should do the trick, but please challenge this requirement, because it doesn't really make sense. It is very error prone, looking at the specific requirement you mention.
It would be very better maintainable to filter on them in a different way, like with a type/category field, so you can just let your reference qualifier look at that field. I don't know which table you are referencing, but it's a specific one, having names with separate words, where the 3rd word contains something. If you just qualify the record as such, it will be a lot easier for you now and way better understandable/maintainable for the future when nobody is around anymore that knows about this.
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2025 03:27 AM
Hi You can use On change Client script and script Include
## Script Include
var FilterReferenceRecords = Class.create();
FilterReferenceRecords.prototype = {
initialize: function() {
},
getFilteredRecords: function() {
var result = [];
var gr = new GlideRecord('table_name'); // Replace 'table_name' with the actual table name.
gr.addActiveQuery(); // Add any other filters if needed.
gr.query();
while (gr.next()) {
var name = gr.getValue('name'); // Assuming the field you are checking is 'name'.
var nameParts = name.split(' '); // Split the name by spaces
// Check if the third word exists and contains 'bdrr'
if (nameParts.length >= 3 && nameParts[2].indexOf('bdrr') !== -1) {
result.push({
sys_id: gr.getValue('sys_id'),
name: name
});
}
}
return result; // Return the filtered records as an array of objects
},
type: 'FilterReferenceRecords'
};
## Client Script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || !newValue) {
return;
}
var ga = new GlideAjax('FilterReferenceRecords');
ga.addParam('sys_id', newValue); // You can pass any necessary parameters here
ga.addParam('name', 'getFilteredRecords');
ga.getXMLAnswer(function(response) {
var filteredRecords = JSON.parse(response);
// Do something with the filtered records. For example, you can dynamically update the list of records
// in the reference field's dropdown or handle it based on your UI needs.
console.log(filteredRecords);
});
}
Best Possible Solution:
-->Script Include handles the business logic on the server-side, which is preferable for performance and maintainability.
-->The onChange Client Script provides a dynamic, real-time way of filtering records based on user input.