Get Count of selected Items and string of select concatenated values from Listbox

Can anyone explain how to get the count of selected items from a listbox?

I also need all of the selected values concatenated in a string to use in a SQL statement?

Do I need to build these values through an iteration of the listbox or are there some functions I can call?

Thanks.

Hi Bradford Jones,

How are you selecting each item in the list? 

In advance, I think you need to build your logic iterating your list or filtering.

But share some code or image so we can provide you some ideas.

Regards,

Marco Arede wrote:

Hi Bradford Jones,

How are you selecting each item in the list? 

In advance, I think you need to build your logic iterating your list or filtering.

But share some code or image so we can provide you some ideas.

Regards,

I have a standard listbox bound to an entity with two fields, status code and selected boolean.
Selection is by clicking on the values in the list and I'd like to get these values in the on change handler.

Thanks.


Bradford Jones wrote:

Can anyone explain how to get the count of selected items from a listbox?

I also need all of the selected values concatenated in a string to use in a SQL statement?

Do I need to build these values through an iteration of the listbox or are there some functions I can call?

Thanks.

Hi Bradford,


You will use the OnChange of the CheckBox that is in the list of the screen.

In the OnChange action, you will execute a ForEach and then an if (checking if the current item is selected).
The item that is selected, you add one more in your selected item counter and then you will concatenate the ID of the current item in a variable.

So you have the total of selected items and also have in a variable all the items that were selected with the concatenated id.


Hugs,

Eduardo

Bradford Jones wrote:

I have a standard listbox bound to an entity with two fields, status code and selected boolean.
Selection is by clicking on the values in the list and I'd like to get these values in the on change handler.

I just wanted to confirm that you are using the normal list and checkbox.

Then I'd suggest (similar to what Eduardo Benites) to do the following approach:

  1. In propery "OnChange" of widget check box, set a new screen action.
  2. In that screen action, place a list filter, to filter the list by the boolean field and corresponding condition
  3. Then save in a local variable the the number of records that are in the list filter

Note that you could also do this with a for each, but this way is more optimized.

And for your second point, could you elaborate a bit more, why you need to concatenate the values?

Marco Arede wrote:

Bradford Jones wrote:

I have a standard listbox bound to an entity with two fields, status code and selected boolean.
Selection is by clicking on the values in the list and I'd like to get these values in the on change handler.

I just wanted to confirm that you are using the normal list and checkbox.

Then I'd suggest (similar to what Eduardo Benites) to do the following approach:

  1. In propery "OnChange" of widget check box, set a new screen action.
  2. In that screen action, place a list filter, to filter the list by the boolean field and corresponding condition
  3. Then save in a local variable the the number of records that are in the list filter

Note that you could also do this with a for each, but this way is more optimized.

And for your second point, could you elaborate a bit more, why you need to concatenate the values?

I need to concatenate the values to pass into a SQL for the IN clause. I will create a string like the following...'ATL','DFW' that will be used in my sql statement

I have been able to do this a for-each but will try the list filter as you suggest.

Thanks


Bradford Jones wrote:

I need to concatenate the values to pass into a SQL for the IN clause. I will create a string like the following...'ATL','DFW' that will be used in my sql statement

I have been able to do this a for-each but will try the list filter as you suggest.

Using list filter is a good way to implement that. 

And to concatenate values for passing to SQL statement, you can append the list items identifiers one by one (and there are different ways of doing so). I see you are using strings, not identifiers correct? And how many values you are appending to the string?