ComboBox on change to filter another ComboBox

ComboBox on change to filter another ComboBox


Table: Geography -> 

Id 1, Country India, Company ABC

Id 2, Country India, Company XYZ

Id 3, Country US, Company DEF


Country combobox - It should populate all the countries from Table Geography (India, US)

Now on selection of India, it should populate ABC, XYZ company in the 2nd combobox.

How can this be achieved with minimal code change? 


I have populated all the Countries in the drop down. In the form preparation -> I have placed an aggregate which gets all the records from the table geography. In the Source Records List in am binding this GetGeographyByCountryName.List and SourceAttribute is Geography.Country.

Now, onselectionchange, i am passing this parameter which takes the countryname like this Form1.Record.CountryName but unfortunately this takes Id 1 if i select India not sure why?

Also how do i display companies on selection of Country in the first drop down.

Thanks for your help in advance.

Awaiting your revert.

Hi Saswata,

It seems you're on the right track. You already have a Combo Box that contains the country names. I assume that you populate it with the Geography Entity directly, or have an Aggregate that queries that Entity, which means that the Source Identifier Attribute will be a Geography Identifier, and so the Variable must also be of Geography Identifier.

You are talking about Form1.Record, so I assume your Combo Box is inside a Form Widget, which means that the Variable must be an Attribute of whatever Entity Record or Structure you have chosen for that Form. From your description however, it seems you have bound it to a CountryName, which is probably a Text Attribute, which explains it receiving "1" instead of "India", as 1 is the Identifier value for that record. Note that Service Studio very likely complains (i.e. gives a TrueChange Warning) if you assign a Variable that's not of type Geography Identifier. Looking at the Warnings is important! Also Note that having the Id, instead of the Text, is typically the right approach. You don't want to save the country name in another Entity, you want to store the Identifier.

Now to your second question, displaying only the companies from the selected country. This is done by filtering the Aggregate that produces the company list. It depends a bit on the way you have set up your Screen and Aggregates what is the best way to handle this. Assuming you have the Aggregate in your Preperation (let's call it GetCompaniesByCountry), add a Local Variable of type Geography Id (let's call it GeographyId). In GetCompaniesByCountry, add a Filter that says "GeographyId = NullIdentifier() or Geography.Id = GeographyId" (assuming the Entity is actually called Geography). In the OnChange if your geography/country Combo Box, set GeographyId to Form1.Record.GeographyId (you don't have that currently it seems, but you need it, see above), and add a Refresh Data Statement that refreshes the GetCompaniesByCountry Aggregate. Next Ajax Refresh the Combo Box containing the companies.

There's no magic in the above, it's all fairly straightforward OutSystems programming. If you need explanations about the details, don't be shy to ask :).


Adding to what Kilian said, there is also an old component in the Forge explaining how to achieve that behaviour.

Check it out here: