Fill second combobox depending on first combobox value

Let me start by saying I did look on the forum and found lots of examples, but none of the examples meets my requirements. I am developing this one on a mobile application and I am on OutSystems 11.

In the order detail screen are 2 comboboxes (main reason and sub reason) available, with which you can indicate why the order was not 100% delivered in one go. The values in the combobox subreason depend on the value selected in the combobox main reason. Some only have a main reason and therefore the subreason should not be shown/greyed out.

I am using the table you can see below in the screenshot (and also attached the .xls so you can maybe use it to test some things). As you can see all the reasons are listed in the name column, but the Id and UnfinishedReasonParentId make the difference here. So basicly if the ParentId matches the Id the corresponding subreasons need to be shown. Let me give an example to be more clear bout what I would like to create:


Main reason to be shown in dropdown 1: 

- Fout aannemer (Id = 1)

When the selection in dropdown is made the sub reasons to be shown in dropdown 2 should be: 

- Verkeerde planning (ParentId = 1)
- Verkeerd ingemeten (ParentId = 1)
- Veel meerwerk (ParentId = 1)
- Schade (ParentId = 1)
- Producten niet in week 1 gecontroleerd (ParentId = 1)
- Installatiefout (ParentId = 1)


By default all reasons are outputted in the combo box as you can in the screenshot below. That seems to be logical because it outputs the whole list and I guess I could do a filter in the aggregate to only show all UnfinishedReasonParendId with value 0 (all main reasons have parentid value 0) but with that solution I seem to able to use the onChange solution I see alot on the forum.


From now on I do not know how to get a second combo box going that outputs the sub reasons depending on the main reason and I hope you can help me with that. Thanks!

Hi Bart Nooijens,

I created a sample app, based on your requirement.

Check this: Cascade Dropdown Demo App Screen


PFA - inlcudes the .oml solution file.


Note:

Category Type Dropdown --> main reason 

Item Dropdown --> sub reason


Hope this helps you!


Regards,

Benjith Sam

Solution

Hello Bart,

You need to use 1 query for each combobox (2 queries) and in the second query for second combobox you need to add a filter to show only the ParentId = <value selected in first combobox>

Please see my example in attachment in web app, you need to adapt to mobile.


Hope it helps,

BR.

Luis

Solution

Hi Benjith and Luis,


Thanks for your quick replies. Basicly you are telling me the same but I seem to not get it working yet. Maybe you can see what I am doing wrong at the moment.

Screenshot of both dropdowns:

Screenshot of both the local variables I made:


Both the Aggregates for Main reasons and subreasons.


Screenshot of the OnChange:

And also a screenshot of the table itself:


Everything resulting in two empty dropdowns, so I am clearly doing something wrong but I am not sure on what I am doing wrong. Hope you can point me in te right direction.


Hi!

In the first query (first dropdown) you don't need to put the filter because you didn't select the value yet.

Can you try to remove it and test it agan?


Bart Nooijens wrote:

Hi Benjith and Luis,


Thanks for your quick replies. Basicly you are telling me the same but I seem to not get it working yet. Maybe you can see what I am doing wrong at the moment.

Screenshot of both dropdowns:

Screenshot of both the local variables I made:


Both the Aggregates for Main reasons and subreasons.


Screenshot of the OnChange:

And also a screenshot of the table itself:


Everything resulting in two empty dropdowns, so I am clearly doing something wrong but I am not sure on what I am doing wrong. Hope you can point me in te right direction.




Luís Cardoso wrote:

Hi!

In the first query (first dropdown) you don't need to put the filter because you didn't select the value yet.

Can you try to remove it and test it agan?


Bart Nooijens wrote:

Hi Benjith and Luis,


Thanks for your quick replies. Basicly you are telling me the same but I seem to not get it working yet. Maybe you can see what I am doing wrong at the moment.

Screenshot of both dropdowns:

Screenshot of both the local variables I made:


Both the Aggregates for Main reasons and subreasons.


Screenshot of the OnChange:

And also a screenshot of the table itself:


Everything resulting in two empty dropdowns, so I am clearly doing something wrong but I am not sure on what I am doing wrong. Hope you can point me in te right direction.




Hi Luis,

I removed the filter but the problem I have is that all mainreasons and subreasons are being shown as they are in the same column (see the excel I attached). So I guess I do need to do some filtering on the first dropdown to only show the mainreasons. Also the second dropdown does not show any data.

Yes, you are correct. You need to add a filter to show only where parentid = 0 or parentid = null in first query.

For second query if you want to show all records before you select one in the first column you need to change the filter to : ParentId = MainResultIdentifier or MainResultIdentifier = nullidentifier() 

Can you try that?

Luís Cardoso wrote:

Yes, you are correct. You need to add a filter to show only where parentid = 0 or parentid = null in first query.

For second query if you want to show all records before you select one in the first column you need to change the filter to : ParentId = MainResultIdentifier or MainResultIdentifier = nullidentifier() 

Can you try that?

I think we are misunderstanding each other now. Let me try to explain a bit better. When I select the main reason in the first dropdown then the second dropdown needs to be filled with subreasons according to the main reason i selected. So I guess I am still missing something somewhere and still no clue where that might be. You still have an idea?


I changed the filter on the first dropdown aggregate and the first dropdown is now showing the correct values.





I understand what you request. You need to refresh the second query to show the values in second combobox in the "onchange" as you are doing. Did you test it on the browser? What happens when you select one record on first dropdown? 

Did you try to debug the code to see what is incorrect? 

Luís Cardoso wrote:

I understand what you request. You need to refresh the second query to show the values in second combobox in the "onchange" as you are doing. Did you test it on the browser? What happens when you select one record on first dropdown? 

Did you try to debug the code to see what is incorrect? 

Ah, the problem could be there. I think I am refreshing the wrong query at the moment. At this point when I select the first dropdown, nothing is happening on the second one. I will let you know what the outcome of this will be. Could be tomorrow though. Thanks for so far!


Correct, you need to refrehs the second query :)


Bart Nooijens wrote:

Luís Cardoso wrote:

I understand what you request. You need to refresh the second query to show the values in second combobox in the "onchange" as you are doing. Did you test it on the browser? What happens when you select one record on first dropdown? 

Did you try to debug the code to see what is incorrect? 

Ah, the problem could be there. I think I am refreshing the wrong query at the moment. At this point when I select the first dropdown, nothing is happening on the second one. I will let you know what the outcome of this will be. Could be tomorrow though. Thanks for so far!




Luís Cardoso wrote:

Correct, you need to refrehs the second query :)


Bart Nooijens wrote:

Luís Cardoso wrote:

I understand what you request. You need to refresh the second query to show the values in second combobox in the "onchange" as you are doing. Did you test it on the browser? What happens when you select one record on first dropdown? 

Did you try to debug the code to see what is incorrect? 

Ah, the problem could be there. I think I am refreshing the wrong query at the moment. At this point when I select the first dropdown, nothing is happening on the second one. I will let you know what the outcome of this will be. Could be tomorrow though. Thanks for so far!




Hi Luis,


I was indeed refreshing the wrong query. Now it works as expected. Thanks!

Hi Bart!

Great news. Glad to help you.

Happy coding


Bart Nooijens wrote:

Luís Cardoso wrote:

Correct, you need to refrehs the second query :)


Bart Nooijens wrote:

Luís Cardoso wrote:

I understand what you request. You need to refresh the second query to show the values in second combobox in the "onchange" as you are doing. Did you test it on the browser? What happens when you select one record on first dropdown? 

Did you try to debug the code to see what is incorrect? 

Ah, the problem could be there. I think I am refreshing the wrong query at the moment. At this point when I select the first dropdown, nothing is happening on the second one. I will let you know what the outcome of this will be. Could be tomorrow though. Thanks for so far!




Hi Luis,


I was indeed refreshing the wrong query. Now it works as expected. Thanks!