how to populate list collector values based on another list collector values

sk59
Tera Expert

Hi All,

I have two list collector variables(countries,sites) on the catalog form/portal from.

I need to populate related sites based on the countries selection.

I have written onchange client script which is working if I select only one country. If i select multiple countries below is not displaying all the sites of those countries.

 

var collectorName = 'site';
var filterString = 'u_country=' +newValue;

try{
g_form.setValue(collectorName, '');
var myListCollector = g_list.get(collectorName);
myListCollector.reset();
myListCollector.setQuery(filterString);

}

catch(e){
window[collectorName + 'g_filter'].reset();
window[collectorName + 'g_filter'].setQuery(filterString);
window[collectorName + 'acRequest'](null);
}

please suggest

1 ACCEPTED SOLUTION

Dubz
Mega Sage

try changing your filter string to the below

var filterString = 'u_countryIN' +newValue;

View solution in original post

6 REPLIES 6

Dubz
Mega Sage

try changing your filter string to the below

var filterString = 'u_countryIN' +newValue;

Thanks David it worked.

How to display only unique values

 

I think you'll have to rethink your method if you've got duplicate records in your site table. Best practice i think would be to use GlideAjax to call a script include and run a glide aggregate in there to group by site name which should remove the duplicates eg:

var arr = [];
var ga = new GlideAggregate('site');
ga.addEncodedQuery(filterString);
ga.groupBy('name');
ga.query();
while(ga.next()){
arr.push(ga.getUniqueValue());
}
return arr;

/* apply filter 'sys_idIN' + answer; in your client script (where answer is what your ajax call returns)

Hi David,

 

This is needed for a different scenario. I have two variable Roles, resposibilities similar to countries and sites.

in this case responsibilities related to that specific roles need to be populated. 

I have the below combination in the table

Role 1    Resp1

Role 2    Resp1

Role 3     Resp2

Role 1     Resp2

 

When i select Role 1 I am getting Resp1,Resp2 in the list when I select one more Role 2 I am getting Resp 1

So I can see finally in the resposibilities Resp1,Resp2,Resp1 again. Here I need to show only unique if the resposibility is already selected I should not show in the list