- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2024 05:11 AM - edited 08-27-2024 02:56 AM
Dear All,
We have two tables, Instance and Alias, with a many-to-many (m2m) table managing their relationship. The Alias table includes a related list of Database records.
Requirement:
We are configuring a service catalog item with two reference fields:
- Instance Field: Points to the Instance table.
- Database Field: Points to the Database table.
We need to show only the related Database records in the "Database" field based on the selection made in the "Instance" field. Specifically, when a user selects an Instance, only those Database records related to the selected Instance (through the Alias table) should be available for selection in the "Database" field.
Request:
How can we configure the "Database" field to dynamically filter its options based on the value selected in the "Instance" field?
Thanks & Regards,
Reddy481.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2024 01:25 AM
Hi @Reddy4811
Let's try the approach to retrieve related Database records for your scenario.
1. Query to the m2m table to get all associated Alias to the Instance (with Alias Sys Id, separated by comma).
2. Return an encoded query with the Alias contains the Sys Id above.
Sample function for the script include
getAliasByInstance: function(instanceSysId){
var alias = [];
var gr = new GlideRecord('<your_m2m_table>');
gr.addQuery('instance', instanceSysId); //replace your instance field name in the m2m table
gr.query();
while(gr.next()){
alias.push(gr.getValue('alias')); //replace your alias field name in the m2m table
}
return alias.join(',');
},
getDatabaseQueryByInstance: function(instanceSysId){
var alias = this.getDatabaseQueryByInstance(instanceSysId);
return 'aliasIN' + alias; //replace the alias field name in the Database table
},
Reference Qual:
//replace your script include name and your Instance variable/field name
javascript: new InstanceUtils().getDatabaseQueryByInstance(current.variable.instance);
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2024 10:44 PM
Please don't tag people in your questions. It's very annoying! And it can have other people ignore your question because it looks like you don't want their help.
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
08-27-2024 01:10 AM
@Reddy4811 You need to create an Advanced reference qualifier on your Database reference field. This Advanced reference qualifier will call a script include method by passing the instance variable as a parameter.
Inside your script include you will query the m2m table to find out the Alias associated with the instance. From the Alias record, you can query the database table to fetch those database sys_ids which are associated with Alias. Finally you will return the comma separated list of sys_ids with
'sys_idIN'+<comma separated list of sys_ids>
Hope this helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2024 03:15 AM
@Reddy4811 The accepted solution follows the exact same approach I have described in my response.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2024 01:25 AM
Hi @Reddy4811
Let's try the approach to retrieve related Database records for your scenario.
1. Query to the m2m table to get all associated Alias to the Instance (with Alias Sys Id, separated by comma).
2. Return an encoded query with the Alias contains the Sys Id above.
Sample function for the script include
getAliasByInstance: function(instanceSysId){
var alias = [];
var gr = new GlideRecord('<your_m2m_table>');
gr.addQuery('instance', instanceSysId); //replace your instance field name in the m2m table
gr.query();
while(gr.next()){
alias.push(gr.getValue('alias')); //replace your alias field name in the m2m table
}
return alias.join(',');
},
getDatabaseQueryByInstance: function(instanceSysId){
var alias = this.getDatabaseQueryByInstance(instanceSysId);
return 'aliasIN' + alias; //replace the alias field name in the Database table
},
Reference Qual:
//replace your script include name and your Instance variable/field name
javascript: new InstanceUtils().getDatabaseQueryByInstance(current.variable.instance);
Cheers,
Tai Vu