Need to populate location field based on the country selection

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.

 

Could you please help me with the script, Im fairly new to scripting and would be a great learning for me.

 

Thanks in advance.

28 REPLIES 28

Hi

Here the exact solution as per your requirement:-

getCountry1 : function ()
{
var sys_id_list=[];
var cou;
var a=current.variables.u_select_country.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();
},

paste the code in your script include like:- 'getCountryLocation'

 

call the script include name and method in your location field in reference qualifier section see the below screenshot:-

find_real_file.png

 

Here the form layout:-

find_real_file.png

 

Also, see the attached attachment 

Regards,

PKG

 

Hi Gupta,

 

I really appreciate your patience and inputs here.

 

I have tried it and it is not working. Still it is populating the locations of all the countries.

 

find_real_file.png

 

ref qualifier:

 

find_real_file.png

 

Can you tell me what am I missing here?

Hi 

You called the script include wrong :-

javascript : new getCountryLocation().getCountry1();

rog
Giga Contributor

I have changed it but still it is not working as expected.

Hi

Your fields is in what scope? because your script include scope is human resource. So please make sure the scope.