Filter Location on the basis country

KS7
Kilo Contributor

Hi All,

I have a dropdown field for the country in catalog item and I wanted to filter location which is a reference field based on the selected location.

I am trying to write a reference qualifier and but values are still not filtering.

function getLocations(country_var) {
var sys_id_list = [];
var gr1 = new GlideRecord('cmn_location');
gr1.addQuery('state', country_var);
gr1.query();
while (gr1.next()) {
sys_id_list.push(gr1.getValue('name'));
}
return 'sys_idIN' + sys_id_list;

}

On location variable - I have added this qualifier javascript: getLocations(current.variables.country)

Any help would be appreciated

 

 

1 ACCEPTED SOLUTION

Hi,

then you don't need script include for this

Your advanced ref qualifier should be like this since you are querying with the state field

javascript: 'state=' + current.variables.country;

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

10 REPLIES 10

Sanjeev Kumar1
Kilo Sage

Hi,

If you see in cmn_location table we have country field you need to use that once user select country.

So you need to use your code like.

 

function getLocations(country_var) {
var sys_id_list = [];
var gr1 = new GlideRecord('cmn_location');
gr1.addQuery('country', country_var);
gr1.query();
while (gr1.next()) {
sys_id_list.push(gr1.sys_id);
}
var sysIDstr = sys_id_list.toString(); 
return 'sys_idIN' + sysIDstr;

}

 

Hi Sanjeev,

 

Due to certain requirements, we're not using the country field on the location table. The value selected by the user in the country field is equivalent to value in state field in the location table.

I am able to return the sys_id's in the logs but the same result is not getting applicable on location field.

 

@KS

please share the screenshot of the variable configuration for both the variables

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Anukur,

Please find the screenshot

So, If I select I wanted to display below 3 location. In the location table, the country and state field is having the same value.

 

find_real_file.png

find_real_file.png