How to call a Script include From reference Qualifier?

Aditya02
Tera Guru

Hi everyone,

I'm trying to dynamically filter reference field values in a Catalog Item based on the selection of another variable. Specifically, I want to pass the Sys ID of a selected building from a variable and use it in a Script Include to filter related data.

 

Here's the use case:

  • I have a variable that captures the Building selection.
  • Based on the selected building's Sys ID, I want to filter the Workplace Services field to show only the services linked to that building.

I am using a Script Include to fetch related services.
🔍Script Include Example:

getWorkplaceServices: function(buildingSysId) {
var categoryList = [];

if (buildingSysId) {
// Query Workplace Services where Building = Selected Building
var grWorkplaceService = new GlideRecord('sn_wsd_case_workplace_service');
grWorkplaceService.addQuery('building', buildingSysId); // Assuming 'building' is the reference field
grWorkplaceService.query();

while (grWorkplaceService.next()) {
categoryList.push(grWorkplaceService.sys_id.toString()); // Store sys_id
}
}

return categoryList.join(','); // Return comma-separated list of sys_ids
},

 

Reference qualifier script:
javascript: new FilterWorkplaceServices().getWorkplaceServices(current.variables.building);

My Question:

Here I am getting sys Id as undefined while i am including addinfomessage to display the sysId.

I want the qualifier to dynamically filter the related Workplace Services based on the selected building.

Any help or example would be greatly appreciated! 🙏

2 REPLIES 2

Nishant8
Giga Sage

Hello @Aditya02 , since you haven's shared your SI complete screenshots, assuming that SI is client callable and you are able to invoke it properly. Here in your code, please change the return statement as following and then try and share the outcome.

 

return

'sys_idIN'categoryList.join(',');

Juhi Poddar
Kilo Patron

Hello @Aditya02 

  • There is nothing wrong with your script when calling a Script Include from a reference qualifier.
  • However, the Script Include should return a query to filter the records instead of just the Sys IDs.

Here’s a small modification to the return statement in your Script Include:

 

return "sys_idIN" + categoryList.join(',');

Note: Script Include should not be client callable.

 

Hope this helps!

 

"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"

 

Thank You
Juhi Poddar