Calculated attribute and combo box

Calculated attribute and combo box

  

Hi all.

I have problem with Calculated Attribute and Combo box usage. What I intended to achieve is that:

1) When user choose on the option (e.g. SIRI 1 - .....) and click on the "Daftar" button, 


2) The output should be following the user's selected choice. Instead, the output is:

It should be SIRI 1 - .... instead of SIRI 8 - ....

It seems that the output will always be the last one found in the Combo box list (Calculated Attribute). For example if there is SIRI 9 - ... , the output will be SIRI 9 - ....


The calculated attribute that I use for the Combo box comes from:

And the other thing that I would like to achieve is that, when user selects SIRI 1 - ... , Kursus.Id value will be 1. The problem now is that it will always be the last one found in the list (SIRI 8 - ... , Kursus.Id value of 8).

When the "Daftar" (refer to Step 1) button is clicked, I assigned the followings:


All values that eventually get created/inserted inside the Daftar Kursus entity is correct except for Kursus.Id and DetailsKursus (as those two values will always be the last one found on the Combo box list):

When user selects SIRI 1 - ... and clicks on the "Daftar" button, the value of Kursus_Id inside the DaftarKursus entity should be 1 and the value inside DaftarKursusDetails inside DaftarKursus entity should be SIRI 1 - ... 


Please assist. Thank you.

You can´t use GetKurses.List.Current.Kursus.Id in the assign of your "Daftar" button.


You should use the variable that is binded to your select. That's the variable that has the selected value.

The value GetKurses.List.Current in your assign will be always the last one in your list, because OutSystems already iterated that list to populate the combobox.


Victor

Victor Salvalagio Pereira wrote:

You can´t use GetKurses.List.Current.Kursus.Id in the assign of your "Daftar" button.


You should use the variable that is binded to your select. That's the variable that has the selected value.

The value GetKurses.List.Current in your assign will be always the last one in your list, because OutSystems already iterated that list to populate the combobox.


Victor

Is there a way for me to achieve what I have outlined earlier? For when SIRI 1 - ... is chosen, then the value that gets saved is SIRI 1 - ... , not SIRI 8 - ...

On top of that, when SIRI 1 - ... gets chosen, I want the value of Kursus.Id that gets saved in DaftarKursus entity to be 1


The variable that is binded to the select is DetailsKursus

The combo box settings

kab wrote:

The combo box settings

The variable that holds "SIRI 1" is TableForAdmin.List.Current.... 

In your button you should use this value, just like you are using in the Peserta_Id.
In Peserta_Id you are using the value from TableForAdmin.List.Current.... that's the right place to get the selected value, as this is the variable binded to your select


Victor Salvalagio Pereira wrote:

kab wrote:

The combo box settings

The variable that holds "SIRI 1" is TableForAdmin.List.Current.... 

In your button you should use this value, just like you are using in the Peserta_Id.
In Peserta_Id you are using the value from TableForAdmin.List.Current.... that's the right place to get the selected value, as this is the variable binded to your select


In my case, I assigned the following as the variable that holds the selected value of the Combo Box

TableForAdmin.List.Current.DaftarKursus.DaftarKursusDetails



I still don't get it why is that:


When SIRI 1 is chosen and Daftar button is clicked, SIRI 8 is saved instead of SIRI 1. I know I made mistake(s) somewhere here.

And how to relate the Calculated Attribute to the Kursus ID? I want Kursus ID 1 points to SIRI 1 (as can be seen in the Calculated Attribute figure that was attached earlier)

Your mistake is in your assign, and it's not related to the calculate attribute.

In your assign, inside your button, you are using the value from your query, and not the one binded to your select:



You should change the value from GetKursueses.List.Current.Kursus.Id to this: 

TableForAdmin.List.Current.DaftarKursus.DaftarKursusDetails

Because that's the variable that holds your selected value.

The query GetKursueses holds all the possible values and not the selected value. The selected value is in 

TableForAdmin.List.Current.DaftarKursus.DaftarKursusDetails



Victor Salvalagio Pereira wrote:

Your mistake is in your assign, and it's not related to the calculate attribute.

In your assign, inside your button, you are using the value from your query, and not the one binded to your select:



You should change the value from GetKursueses.List.Current.Kursus.Id to this: 

TableForAdmin.List.Current.DaftarKursus.DaftarKursusDetails

Because that's the variable that holds your selected value.

The query GetKursueses holds all the possible values and not the selected value. The selected value is in 

TableForAdmin.List.Current.DaftarKursus.DaftarKursusDetails



This happens when I apply your suggestions:

Then upon selecting the option and clicking on the "Daftar" button:

DaftarKursusDetails is in Text while Kursus.Id is in Long Integer

Hi Kab,

I believe there's a mistake between source attribute and identifier attribute in the combobox definition.


The logic should be the following:
Source attribute:    Should be the calculated attribute that is being displayed to the user
Identifier attribute: Should be the selected DaftarKursus identifier and not the calculated attribute.


After changing the variable to the identifier value (should be TableForAdmin.List.Current.DaftarKursus.Kursus_Id from what I saw in the screenshots) you don't need to do the last assign as the value is already mapped to the correct variable once you press the button and you just need to continue with your logic.

That would do it for the KursusID mapping, to get the DaftarKursusDetails you can get the calculated attributed value based on selected identifier (either by using a Query or using a list filter, for large results a query would have a better performance).


Let me know if something is unclear, hope it helps!

Paulo Jadaugy wrote:

Hi Kab,

I believe there's a mistake between source attribute and identifier attribute in the combobox definition.


The logic should be the following:
Source attribute:    Should be the calculated attribute that is being displayed to the user
Identifier attribute: Should be the selected DaftarKursus identifier and not the calculated attribute.


After changing the variable to the identifier value (should be TableForAdmin.List.Current.DaftarKursus.Kursus_Id from what I saw in the screenshots) you don't need to do the last assign as the value is already mapped to the correct variable once you press the button and you just need to continue with your logic.

That would do it for the KursusID mapping, to get the DaftarKursusDetails you can get the calculated attributed value based on selected identifier (either by using a Query or using a list filter, for large results a query would have a better performance).


Let me know if something is unclear, hope it helps!


Hi Paulo,


Your suggestion works and I'm still having trouble to figure this part: to get the DaftarKursusDetails you can get the calculated attributed value based on selected identifier (either by using a Query or using a list filter, for large results a query would have a better performance).

Do you mind to clarify further on this? Thank you.

1) Lets say User selected the first option (SIRI 1 - ...)


2) But upon clicking on the "Daftar" button, SIRI 3 - ... gets saved instead


3) From the database point of view, the correct Kursus_Id has been inserted into DaftarKursus entity. The only problem left now is on the DaftarKursusDetails (supposed to be SIRI 1 - ... instead of SIRI 3 - ....)

Solution

Hi Kab,

Sure I can clarify further, now that you have the selected ID you can run a query similar to the GetKursUses but you filter the list with the selected ID.

In the filters you add the condition ID = TableForAdmin.List.Current.DaftarKursus.Kursus_Id and then you assign the output of that query with the calculated attribute to the details column.

TableForAdmin.List.Current.DaftarKursus.DaftarKursusDetails = KursusById.list.Current.CalculatedAttribute (something like this).

Afterwards both values will be correct.

The alternative is to use the ListFilter from system actions that filters a query in memory (source record is GetKursUses.List) using the criteria
Id = TableForAdmin.List.Current.DaftarKursus.Kursus_Id

And getting the details column from the output result that comes from ListFilter.


Hope that helps!


Solution

Paulo Jadaugy wrote:

Hi Kab,

Sure I can clarify further, now that you have the selected ID you can run a query similar to the GetKursUses but you filter the list with the selected ID.

In the filters you add the condition ID = TableForAdmin.List.Current.DaftarKursus.Kursus_Id and then you assign the output of that query with the calculated attribute to the details column.

TableForAdmin.List.Current.DaftarKursus.DaftarKursusDetails = KursusById.list.Current.CalculatedAttribute (something like this).

Afterwards both values will be correct.

The alternative is to use the ListFilter from system actions that filters a query in memory (source record is GetKursUses.List) using the criteria
Id = TableForAdmin.List.Current.DaftarKursus.Kursus_Id

And getting the details column from the output result that comes from ListFilter.


Hope that helps!



Thanks for your tips Paulo! Everything works fine as it should be now!