ListBox SelectionAttribute difficulties

I have used the following demo project to attempt to set up a list box, and then have a button identify which item is selected in the list box:

https://www.outsystems.com/forge/Component_Overview.aspx?ProjectId=3955

The demo project works as expected, so I tried using it as a template in my own project. The problem I am having is that I can't get which entries in the list box have been selected. Here is what I have done in my own project:

 PREPARATION 

I create an aggregate, which has a table and an extra Boolean column that defaults to false and is called 'isSelected'

ListBox

Source Record List: myAggregate.List

Source Attribute: Field1

Selection Mode: Single

Selection Attribute: isSelected

Screen Action

For Each: ListBox.List

     Evaluate 'If' Statement: ListBox.List.Current.isSelected

          if true, update a db entry & start next loop 

          if false, start next loop


My problem is that when I call the screen action, ListBox.List is empty. My understanding is that at runtime, in order to see whether an item in the list box is selected, I have to look at the selection attribute field in the listbox list, rather than in the aggregate. Can some help me understand why I can have records in the aggregate, which are displayed in the list box, but ListBox.List is empty?


Thanks,


Ryan

Is it a multi select list box or single select?

Sourav Pasari wrote:

Is it a multi select list box or single select?

Single


Hi Ryan,


I can't really see anything wrong with your approach, could you share the oml or make a sample oml that shows this behaviour ?


Dorine


you can export your project into an oml file from service studio, go into the module and then choose module, export, save as

Hello Ryan

I did a simple example (see attachment) and couldn't reproduce your problem.

Usually, this behaviour happens when the platform thinks you are not using the values, so the values are not stored in the ViewState of the page to improve performance (less traffic on request/response).

Cheers.

Here is an example .oml where I reproduce my error. Here are steps to reproduce:

In debug mode, type the value 1 into the text box. The 'OnTextBoxChange' screen action will fire and the list box will be populated with 3 values (test1, test3, and test5). 

Select any one of the values in the list box. OnListBox1Change screen action will fire. The screen action is supposed to iterate through ListBox1.List and save the selected record to a session variable. The problem is that ListBox1.List is empty. Can anyone tell me why there are no values in ListBox1.List?

Hi Ryan,

Two things.

1. Change the Ok button method to Ajax Submit

2. Change this expression:

"issue " + Session.SelectedRecord.Issues.IssueDescription = " is selected"

to

"issue " + Session.SelectedRecord.Issues.IssueDescription + " is selected"

After this, it should work.

Cheers.

Hi Eduardo,

Thanks for the quick reply. You were correct about those two things needing fixed. However, the real problem is still there. Inside the OnListBox1Change screen action, ListBox1.List is empty, so when the screen action uses a for each loop to look through every record in ListBox1.List to find the one that is selected, and save a copy of it to a variable, it can't find the selected record because the list itself is empty.

Thanks,

Ryan

Hi both,

I don't know why, maybe something with optimization of the aggregate, but if I change your code Ryan, to make sure that at the moment of preparation, the textbox variable has a value (done it by setting a default value in it) then it works !

Can you maybe explain this Eduardo ?

Dorine

Aah,

probably something to do with the textbox being text and the customer id being long integer !!

If your variable would be also a long integer, then the 'nullvalue' would be a 0, not "", and then maybe would work, I'll give it a try

Yes, 

that's it !

with the variable changed to long integer, even without a default value, it works.


I still find it intriguing how such a thing can result in the listbox showing the values retrieved after consecutive refreshes, but not having them available in the flow for coding against...

Here it works as it is, without the need to change the variable.

Just setting the submit to ajax and fixing the expression, everyhting starts to work, and when I debug the OnChange of the ListBox, after the changes, the list is populated.

Cheers.

Eduardo Jauch wrote:

Here it works as it is, without the need to change the variable.

Just setting the submit to ajax and fixing the expression, everyhting starts to work, and when I debug the OnChange of the ListBox, after the changes, the list is populated.

Cheers.

Hi Eduardo,

I don't know what I am doing wrong, but I downloaded a fresh copy of the .oml file I uploaded, changed the '=' to a '+' in the expression (pic1), and changed the submit to ajax (pic2), but when I run the program, the description of the selected record is not placed in the feedback message (pic3). If I debug the OnListBox1Change screen action (pic4), ListBox1.List is still empty.




Solution

Hi Ryan,

I think we stumble on something here...
Could you make a test?

In the ForEach, set the Start Index to 0 and the Max Iterations to ListBox1.List.Length, like this:

Publish and test it again.
It seems that previously I got "lucky" and it did work, but later I tested again, after the session ended, without publishing, and it stopped working.

With the settings above I made it work consistently.

It seems a problem with the optimization of the platform...
I'll pass this to the team to see what they can tell.

Cheers.

Solution

Eduardo Jauch wrote:

Hi Ryan,

I think we stumble on something here...
Could you make a test?

In the ForEach, set the Start Index to 0 and the Max Iterations to ListBox1.List.Length, like this:

Publish and test it again.
It seems that previously I got "lucky" and it did work, but later I tested again, after the session ended, without publishing, and it stopped working.

With the settings above I made it work consistently.

It seems a problem with the optimization of the platform...
I'll pass this to the team to see what they can tell.

Cheers.

Thank you Eduardo! I won't be forgetting to set iterations any more.