Reference Qualifier in a Reference field using different tables

beatricelopes
Tera Contributor

 

Hello everyone!

Today, I'd like to discuss a significant issue I'm currently facing


Let's begin with the context: I have a field named SAP Instance which is a reference field requiring specific information from the Application table for population

 

Initially, I utilized the reference qualifier:
nameLIKEsap^ORnameLIKESolution Manager^ORnameLIKECloud Connector^ORnameLIKEX4D - Other integrations^ORnameLIKEX4Q - Other integrations^ORnameLIKEX4P - Other integrations^operational_status=1^EQ

 

This worked well, displaying the correct information in the field

 

 

However, a new requirement surfaced, requesting an additional filter on the same field. This new filter should display the same specific information but exclude application names that do not match the "Requesting Region" field

 

I attempted to use javascript: 'sap=' + current.requesting_region; in the reference qualifier, but unfortunately, it isn't working. The SAP Instance field references the cmdb_ci_appl table, while the Requesting Region field references cmn_location.

Initially, I wanted to avoid using script includes to resolve this issue, but it seems that might be the necessary path now. Does anyone have any ideas on how to address this?

 

1 ACCEPTED SOLUTION

-O-
Kilo Patron
Kilo Patron

I am assuming that the application names contain both the location name and one of those strings in the existing reference qualifier, so the application names are something like New York SAP or Delhi X4D, in which case the reference qualifier could be something like:

javascript: 'nameLIKE' + current.requesting_region.name + '^nameLIKEsap^ORnameLIKESolution Manager^ORnameLIKECloud Connector^ORnameLIKEX4D - Other integrations^ORnameLIKEX4Q - Other integrations^ORnameLIKEX4P - Other integrations^operational_status=1^EQ'

 

It would help if you could show a representative sample application name.

 

Of course ideally you would NOT filter by Name (name), but attach some information to some field on Application [cmdb_ci_appl], like a flag in field Attributes (attributes) and filter by that instead of Name (name) and applications contained location information in field Location (location) and you would match that and filter against Requesting Region (requesting_region).

View solution in original post

4 REPLIES 4

Anil Lande
Kilo Patron

Hi,

you can use location field like below:

There is location field on cmdb_ci_appl table.

 

javascript: 'location=' + current.requesting_region.toString()

 

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

To learn more about reference qualifiers check below links:

https://www.servicenow.com/community/now-platform-articles/improving-advanced-reference-qualifier-pe...

https://docs.servicenow.com/bundle/vancouver-platform-administration/page/script/server-scripting/co...

 

https://www.servicenow.com/community/itsm-articles/reference-qualifier/ta-p/2306509

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Rajdeep Ganguly
Mega Guru


Sure, you can use a dynamic reference qualifier to achieve this. Here are the steps:

1. Create a new Script Include that extends the GlideAjax class. This script will be used to fetch the data from the server side and send it to the client side.

javascript
var GetApplications = Class.create();
GetApplications.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getApplications: function() {
var region = this.getParameter('sysparm_region');
var apps = new GlideRecord('cmdb_ci_appl');
apps.addQuery('operational_status', 1);
apps.addQuery('name', 'LIKE', 'sap');
apps.addQuery('name', 'LIKE', 'Solution Manager');
apps.addQuery('name', 'LIKE', 'Cloud Connector');
apps.addQuery('name', 'LIKE', 'X4D - Other integrations');
apps.addQuery('name', 'LIKE', 'X4Q - Other integrations');
apps.addQuery('name', 'LIKE', 'X4P - Other integrations');
apps.addQuery('location', region);
apps.query();
var appSysIds = [];
while (apps.next()) {
appSysIds.push(apps.sys_id.toString());
}
return appSysIds.join(',');
},
type: 'GetApplications'
});


2. On the client side, use the GlideAjax object to call the server-side script and get the data.

javascript
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('GetApplications');
ga.addParam('sysparm_name', 'getApplications');
ga.addParam('sysparm_region', g_form.getValue('requesting_region'));
ga.getXMLAnswer(function(answer) {
var appSysIds = answer.split(',');
g_form.clearOptions('sap_instance');
for (var i = 0; i < appSysIds.length; i++) {
g_form.addOption('sap_instance', appSysIds[i], appSysIds[i]);
}
});
}


3. Add this client script to the form where the SAP Instance field is located. Make sure to set the "onChange" checkbox and select the "Requesting Region" field.

This script will clear and repopulate the SAP Instance field options every time the Requesting Region field changes. The options will be limited to the applications that match the selected region.


nowKB.com

For asking ServiceNow-related questions try this :
For a better and more optimistic result, please visit this website. It uses a Chat Generative Pre-Trained Transformer ( GPT ) technology for solving ServiceNow-related issues.
Link - https://nowgpt.ai/

For the ServiceNow Certified System Administrator exams try this :
https://www.udemy.com/course/servicenow-csa-admin-certification-exam-2023/?couponCode=NOW-DEVELOPER

-O-
Kilo Patron
Kilo Patron

I am assuming that the application names contain both the location name and one of those strings in the existing reference qualifier, so the application names are something like New York SAP or Delhi X4D, in which case the reference qualifier could be something like:

javascript&colon; 'nameLIKE' + current.requesting_region.name + '^nameLIKEsap^ORnameLIKESolution Manager^ORnameLIKECloud Connector^ORnameLIKEX4D - Other integrations^ORnameLIKEX4Q - Other integrations^ORnameLIKEX4P - Other integrations^operational_status=1^EQ'

 

It would help if you could show a representative sample application name.

 

Of course ideally you would NOT filter by Name (name), but attach some information to some field on Application [cmdb_ci_appl], like a flag in field Attributes (attributes) and filter by that instead of Name (name) and applications contained location information in field Location (location) and you would match that and filter against Requesting Region (requesting_region).