Need to populate location field based on the country selection
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2018 07:04 PM
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.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2018 02:40 AM
How to achieve this when we have list collector in country instead of reference field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2021 04:00 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2018 09:41 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2018 10:06 PM
Please refer this for reference
https://docs.servicenow.com/bundle/geneva-servicenow-platform/page/script/server_scripting/task/t_JavaScriptCalls.html
Thanks,
Vinu