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

rog
Giga Contributor

How to achieve this when we have list collector in country instead of reference field.

Hi 

just a small doubt,why are you returning 'sys_idIN' and also what is the purpose of appending 'IN' with sys_id.

Best Regards,

pavan

Jaydeep Parmar
Kilo Guru

Call on demand script include from the reference qualifier  as below

javascript:getLocations(current.variables.u_country_var)
// here u_country_var refers to variable name of your country.

Now check with the below script include

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

}


Thanks & Regards,

Jaydeep Parmar.

Vinu1
Tera Expert

Please refer this for reference

https://docs.servicenow.com/bundle/geneva-servicenow-platform/page/script/server_scripting/task/t_JavaScriptCalls.html

 

Thanks,

Vinu