Use of a combo box in a form

Use of a combo box in a form

  

Hello

I pretend to use a combox that  collect a list from one entity (A) and when the user select one option thru a onChange action I populate the attributes of the the form (of the entity B).


The attributes use in the combo box belong to the preparation of entity B


I would appreciate some help


TIA



I Must add that with this solution I am getting always the fields populated with date from the last record of entity A

Hello Alberto, 

One way to do that is to have a foreign key that links one entity to another and then in the combobox properties, set the Source Identifier Attribute. Then you just need to fetch the data you want based on that identifier.

Hope this helps.

Best Regards

Thanks Zacarias

I understand you solution. But in that case I want to avoid it. The two entities must keep isolated


But Thanks for your nice contribution

The variable is strange of your combo is strange.

imho, you should have some local variable.


and it depends how you refresh the form, there are some quirks with it regarding refreshing the form.

so, also use something like "Form1.record = newly fetch record"

then do the refresh



Thanks J.

But I didn't fully understand what you mean with strange.


To refresh the form I in a action (on change of comb box) i assign the values from entity B into the form fields, Follow by and ajax instruction.


At the end if the user pretend can cancel or save the form contents



Hi Marcelo,

J. Is right.

First thing, if you are populating the form with fields from entity B in the combo box in the OnChange, you need to do this in the OnChange:

1. Filter your entity B based on the information provided in the combo box selection (probably A.Id).
2. Use an assignment to associate the B record to the form.Record.B record.
3. Ajax Refresh the form

The form, after the first rendering when the page loads, never go fetch the source again so, if you need to change values in the form, you need to change directly into the form record and refresh the form or the inputs.

Also, note that using an aggregate defined in the preparation in another screen action is bad practice, as you will increase the size of the view state. In this case, as you are dealing with a SINGLE record, probably the performance decrease will not be a problem, but anyway, I usually would use an aggregate in the OnChange to fetch the new data.

Cheers,
Eduardo Jauch

EDIT

What I am missing here is what is the problem you are having :)

Thanks Eduardo.

I will analyse your suggestion.


with strange i meant..


you have a list of values (GetVMAServicesList)

you assign the variable to of your combobox to that same list, only the current in the list.

(normally the last one in the list, but tbh it's not something to use lightly)

-> if you change the dropdown, the id of the current of the vma-list on the server  will be overwritten with the selected id. (that is strange, no? )


what you should have done at least, have a local variable called

"SelectedVMAServicesId" with type VMAServices Identifier

that is the variable you should have assigned in the "variable" of the combobox.

J. wrote:

with strange i meant..


you have a list of values (GetVMAServicesList)

you assign the variable to of your combobox to that same list, only the current in the list.

(normally the last one in the list, but tbh it's not something to use lightly)

-> if you change the dropdown, the id of the current of the vma-list on the server  will be overwritten with the selected id. (that is strange, no? )


what you should have done at least, have a local variable called

"SelectedVMAServicesId" with type VMAServices Identifier

that is the variable you should have assigned in the "variable" of the combobox.

I must confess that I even didn't noticed that the variable associated with the ComboBox was a field of the aggregate...

This is very uncommon, Marcelo.
The usual, when you have a combo box that will not provide values directly to the form, is to bound it to a local variable, like J. said.

Cheers,
Eduardo Jauch

Solution

Thanks for all yours contributions.


With yours suggestions I fund a working solution. I append one example. I hope it is what you have suggested.


Thanks again

Solution

Hello Alberto :)

Sorry, Only had time to see the code now.

So, when you select an ID of entity 2, you want to replace the Ref11 and Ref12 of entity 1 with the values of Ref21 and REf22 of entity 2?
Ok. So, your code looks correct.

I would like to point only a single aspect.

When you enter this screen passing an ID of entity 1, the form will have values.
But the combo box won't.

This is not exactly a problem. But I feel a little bit weird about it, because you can chose an entity 2 record and change Ref11 and Ref12 using data from the other entity.

So, my "weird feeling" is that while the entities do NOT have a relationship, the combo box give the sensation they have.

So, the only thing I would try to do is that in the interface this be more clear, like, to be obvious to the user that he is just picking values from other source :)

Cheers,
Eduardo Jauch

Thanks very much for your comments Eduardo. I understand your reserves to this solution.

There is any way that I can pre-select one option in the combo box based in the record of the entity 1 (probably in the screen preparation action) ?


Best regards 

AJF

Hi Alberto,

The only way I see to this to happen is to do an aggregate to Entity2, and filter it by the references coming from Entity1.

Than, get the Record Id and set the combo box bounded variable to it :)

Thanks Eduardo