Choices of location should be made available based on the country selected in the list collector field.

rog
Giga Contributor

Hi all,

 

I have a requirement where in we need to populate the location (reference to cmn_location) value based on the selection of country (reference to core_country). If for example countries Japan and China are selected then on the locations that are active under these countries should be available for selection in location field.

 

I got to know that we need to achieve this through script include and advance reference qualifier since the location field is a reference field. Please note that the country field is a List Collector.

 

Based on the inputs we have written the below code:

 

var getCountryLocation = Class.create();
getCountryLocation.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCountry1 : function ()
{
var sys_id_list=[];
var cou;
var a=current.variables.countries.getDisplayValue();
var gr1=new GlideRecord('cmn_location');
gr1.addQuery('country',a);
gr1.query();
while(gr1.next())
{
sys_id_list.push(gr1.getValue('sys_id'));
}
return 'sys_idIN'+sys_id_list.toString();
},

type: 'getCountryLocation'
});

 

calling it in the reference qualifier,

javascript : new getCountryLocation().getCountry1();

please suggest. Thanks in advance.

1 ACCEPTED SOLUTION

Jim Coyne
Kilo Patron

You should be able to just set the "Reference qual" field to:

javascript:"country=" + current.variables.countries.getDisplayValue();

View solution in original post

20 REPLIES 20

Joni5
Tera Expert

Have you tried this with just a single country?

You're basically querying locations where country field contains Japan and China.

You should also log what you're doing, so you can see what is causing issues. Then just check the log for what was logged.
Something like this: 

var getCountryLocation = Class.create();
getCountryLocation.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCountry1 : function ()
{
var sys_id_list = [];
var a = current.variables.countries.getDisplayValue();
gs.log('LOG 1 countries: ' + a);
var gr1 = new GlideRecord('cmn_location');
	gr1.addQuery('country',a);
	gr1.query();
	while(gr1.next()){
		gs.log('LOG 2 sys_id for ' + gr1.name + ' is ' + gr1.sys_id);
		sys_id_list.push(gr1.getValue('sys_id'));
	}
return 'sys_idIN'+sys_id_list.toString();
},

type: 'getCountryLocation'
});

 

rog
Giga Contributor

Hi Joni,

 

I have tried by putting in the logs and nothing is coming up in the logs.

Hmm, on your reference qualifier you have a space after javascript. Try removing that.

You'll also need to separately check the countries in your query.

Now you're saying 'gr1.addQuery(country is Japan, China);

rog
Giga Contributor

I got an error log like this 

 

org.mozilla.javascript.EcmaError: "getCountryLocation" is not defined.
Caused by error in <refname> at line 1

==> 1: new getCountryLocation().getCountry1();