- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2018 08:58 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. 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.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2018 08:39 PM
You should be able to just set the "Reference qual" field to:
javascript:"country=" + current.variables.countries.getDisplayValue();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2018 04:33 AM
Correct. A Script Include is NOT required in this scenario. But, as Joni mentioned, the "Reference qual" field should be:
javascript:"countryIN" + current.variables.countries.getDisplayValue();
...with "IN" because there may be multiple countries selected in the List Collector.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2018 12:26 AM
Ah, yes, indeed the simplest solution is the best. Can't believe I basically forgot this while focusing on the script include.
javascript:"countryIN" + current.variables.countries.getDisplayValue();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2018 01:31 AM
I have tried it but now it is returning empty locations. what am i missing here?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2018 01:53 AM
This should definitely work as I tested it as well.
Make sure your variable is called 'countries'.
The current.variables.countries.getDisplayValue() returns the display value of those so for example China and Japan.
Then make sure your cmn_location table actually contains locations where country is Japan or China.
If no such location exists, then you'd end up with 0 results.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2018 08:05 PM
Is it not working because the countries field is a list collector and the location field is a reference field?