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

Hi,

is your Country variable a lookup select box with reference?

what is the Lookup value field for this variable?

That would help you determine the query

Regards
Ankur

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

Hi,

you should be pushing the sys_id instead of name in the array as your 2nd variable is reference type to cmn_location table

sys_id_list.push(gr1.getValue('sys_id'));

Regards
Ankur

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

Tried pushing the sys_id instead of name also, still it's not working.

Is there are issue the way I am calling the script include

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

 

find_real_file.png

Hi,

what type of variable is Country?

Is it lookup select box with reference to some table?

If yes then what is the lookup value field for that?

That would help form your query

find_real_file.png

Regards
Ankur

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

Hi Ankur,

 

Country is a simple select box with two choice values

find_real_file.png