Filter List Of Structure
Application Type
Reactive

Hello, I have a list of structure,  where the Structure is like the following: (Id, Fruit).

So, a list could be for example:

1, Apple

1, Apple and Banana

1, Apple and Banana and Pear

2, Pineapple

2, Pineapple and Banana

1, Just Apple

I want to filter it in order to obtain:

2, Pineapple and Banana

1, Just Apple


So, I want the LAST instance in the list for every id. Does anyone have any idea how to achieve this? Thank you

Solution

Yes.

Add a local variable of type List of Integer

ListAppendAll from the source list to the local variable with the id value

ListDistinct gives you then all unique ids.

Do the foreach

I modified the sample oml to use a foreach loop. Here it is

GridWork.oml

Oh a Low Code Dojo :-) I like Dojos.

A way is to use ListFilter (either hardcoded or in a foreach loop) with a condition of Id = 1.

The last entry is the one you want which translates to List[List.Length -1]

See an oml with an example.

Best

Stefan

GridWork.oml

Hey Stefan! Thank you! I am trying to do this in a ForEach loop (since I actually have a dynamic number of IDs), but I assume that for this I need a list of all my ID's. Is there any way I can do a ListDistinct of my list, to get all the distinct ID's? So distinct by ID, but not distinct by fruit.

Solution

Yes.

Add a local variable of type List of Integer

ListAppendAll from the source list to the local variable with the id value

ListDistinct gives you then all unique ids.

Do the foreach

I modified the sample oml to use a foreach loop. Here it is

GridWork.oml

I understood, thank you very much for your help Stefan, that's what I needed ☺

mvp_badge
MVP

Hi,

Where is this list of data originating from? If it is read from a database, it is preferable to use SQL to make the right selection of records.

Regards,

Daniel

Hi Daniël. This data comes from user input, from a child block to the parent screen. When the inputs reach the parent screen, they are all stored in a list. So, no database involved. Thank you!

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.