Creating Dependency Between Two Glide List Fields
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10 hours ago
Suppose I have two Glide List type fields: Category and Sub-category, each with three choices — A, B, and C. The requirement is:
- When the user selects A in the Category field, only A should be visible in the Sub-category field.
- Similarly, selecting B or C in Category should restrict Sub-category to show only the corresponding value (B or C respectively).
In other words, the Sub-category field should dynamically display only the value that matches the selected Category.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
5 hours ago - last edited 5 hours ago
Sorry, when you referenced choices I didn't make the connection that these are both glide list fields. In this case you would need to use a advanced reference qualifier on the Dependent field and call a script include to return the list of records.
The advanced reference qualifier would look like this:
javascript:'script_include_name.getValues(current.category_field)'
the 'script_include_name' and 'getValues' are both determined by the script include itself and can be changed to whatever you want they just need to be consistent across the script include and the advanced qualifier.
The script include would look something like this:
var script_include_name = Class.create();
script_include_name .prototype = Object.extendsObject(AbstractAjaxProcessor, { //if you are inside a custom scope and not global then it needs to be Object.extendsObject(global.AbstractAjaxProcessor
getValues: function(category) {
var sysIDs = [];
var gr = new GlideRecord('table_name');
var gr.addQuery('category_field_name', category);
gr.query();
while (gr.next()) {
sysIDs.push(gr.sys_id.toString());
}
return 'sys_idIN' + sysIDs.join(',');
},
type: 'script_include_name'
});
This assumes that the list of records to be returned has a reference field associated with the category field so the query effectively says return all records with the same category field. It then formats the list of records' sys_ids and returns them in the correct format to be the options for the sub-category glide list field.
This is specific to a use case where you only ever have 1 category value which it seems might not be the case. It would be helpful to have more details on the exact use case because your chosen terminology is confusing since a glide list field doesn't have choices, it is a reference field that can reference more than one record on the target table.