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

Prins Kumar Gup
Giga Guru

Hi,

Please write the below code in the script include:-

function getCountry()
{
var sys_id_list=[];
var cou;
var a=current.variables.u_requested_for.country;
var gr1=new GlideRecord('sys_user');
gr1.addQuery('country',a);
gr1.query();
while(gr1.next())
{
sys_id_list.push(gr1.getValue('sys_id'));
}
return 'sys_idIN'+sys_id_list;

}

and call the script include a name in the reference qualifier section

find_real_file.png

and also try the below code in your country field:-

javascript: country=current.field_name.getDisplayValue(); 

 

Regards

PKG

We need to take the country value from the selected country in the "country" field not from the user country.

Okay, Just change the table name.

there is another field 'u_country' whatever the country selected in that field, location field should only show the locations present from the countries selected in the countries field which is a slush bucket.

Okay, I will give the exact solution next couple of minutes.