Hello Community, thank you in advance for your input.

I was following the web developer course and in there the data modeling(one to many, many to many) is handled in a very specific way. Were inside the form you just add an input and then an add button, and then a list is displayed  on the bottom via an expresion, and you add one by one the actores,crew, directors or producers.

I was wondering if we could use a list-box with  a dropdownSelect in order to choose from a preexisting list of options to be added and displayed into a list view. 


I actually have tried this, I have a main entity a junction entity and an entity with the options I want to associate with.

I've actually successfully created a listbox that displays all the options that need to be displayed and selected, I just have to problems.

I am not able to save the data of the selected options(inside the form)  and I am not able to make this listbox a mandatory field. 

Is there any way to do this? or is this not the recommended approach?

Hi Juan,

The fastest way to get a good answer is if you can share the application (.oap) then for someone it is easier to see what needs to be changed.

Regards,

Daniel

Hi Daniel! thanks for the tip! I'll certainly create a project I can share and post it in here as soon as I can,

Best Regards,

Juan Montemayor

Sorry for the delay, but I created a quick simple sample project to show you were I am at. right now if you try to save a new record it will show the error, this can be fixed if you change the attribute in the "Main Table"  called "Entity B options" to "nonMandatory". But then the record won't be saved. 

Hi Juan,

When using a listbox with single or multiselect you need to add an extra calculated attribute with default value False to the GetEntityB aggregate in the preperation of the detail screen, instead of the boolean attribute you added to the entityB.

In the preperation you have to to also ensure that for any existing MainTable record you edit the IsSelected attribute  on the GetEntityB aggregate is set to true.

In the Save action you have to filter the listbox on the IsSelected attribute and use a foreach to create/update all maintable records(one for every EntityB option you selected in the listbox.

I added comments in your code, on the detail screen, the preparation, the save action and the entity model.

Attached is the changed application.

Regards,

Daniel

Hi Juan,


The Listbox does not map to any variable of the form directly especially when you have multi select.

You can have a local variable of type Record List of EntityB and IsSelected


On Change of Listbox have an action

 

store the list of selected ids in a variable list 


And while saving save the same record with multiple times changing the selected Ids

Regards,

Saugat

Thank you, great suggestions,  I'll try both solutions today!  Thank you Saugat and Daniel, I'll let you know how this goes.

So I see that this method creates a record for each selected option, does the way of making this work out would be  to create a "Groupby statement" ? Or is there a form we could just change this behaviour, maybe with a junction entity?

Daniël Kuhlmann wrote:

Hi Juan,

When using a listbox with single or multiselect you need to add an extra calculated attribute with default value False to the GetEntityB aggregate in the preperation of the detail screen, instead of the boolean attribute you added to the entityB.

In the preperation you have to to also ensure that for any existing MainTable record you edit the IsSelected attribute  on the GetEntityB aggregate is set to true.

In the Save action you have to filter the listbox on the IsSelected attribute and use a foreach to create/update all maintable records(one for every EntityB option you selected in the listbox.

I added comments in your code, on the detail screen, the preparation, the save action and the entity model.

Attached is the changed application.

Regards,

Daniel


Hey Daniel, I think I'll use your solution, I think I still have some questions, but still it is very helpful, thank you very much!  Do you know if I can make the listbox a mandatory field(required? compulsory?)

Saugat Biswas wrote:

Hi Juan,


The Listbox does not map to any variable of the form directly especially when you have multi select.

You can have a local variable of type Record List of EntityB and IsSelected


On Change of Listbox have an action

 

store the list of selected ids in a variable list 


And while saving save the same record with multiple times changing the selected Ids

Regards,

Saugat

Hello,


The logic is good, however we can reduce the logic by simply using ListFilter and it will give us the values that are selected in a list.