How to split Comma separated values
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2019 12:44 AM
Hi All,
I am returning multiple location values under each country like below which has comma
Country A - av, mexico
Country A - abo,vig,abanaro
I need to get these locations when a specific country is selected and display only those locations.
As the locations include comma(,) how do I split and display
I am able to get the values like av, mexico,abo,vig,abanaro in the logs
but how do I set it in the locations field?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2019 12:58 AM
Hi
Can you share you code?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2019 02:35 AM
this is an on change client script i.e when country changes respective locations should populate
var countryIds = g_form.getValue('country');
var siteIds = g_form.getValue('site');
siteIds = siteIds.split(',');
if (siteIds && siteIds.length) {
getSiteIds(countryIds, function (response) {
response = response ? response.split(',') : [];
alert('siteIds '+response);
siteIds = siteIds.reduce(function (acc, siteId) {
if (response.indexOf(siteId) !== -1) {
if (acc.indexOf(siteId) === -1) {
acc.push(siteId);
}
}
return acc;
}, []).join(',');
g_form.setValue('site', siteIds);
});
}
}
here the funtion getSiteIds returns the values like below from the script include
AM, Acindar,Ternium, San Nicolas de los Arroyos
where
AM, Acindar -location 1
Ternium, San Nicolas de los Arroyos - location 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2019 12:59 AM
Hi
Add those location values into an array and display array values with comma.
e.g
var locations= [];
locations.push('av');
locations.push('mexico');
locations.toString();
gs.print(fruits); o/p : av,mexico
as like above you can push values whatever u have and display.
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2019 12:59 AM
You can use split function of javascript inside your code if it is in string format.