How to verify item present in list or not?

How to verify item present in list or not?

  

Hi,

I have list of text and I am adding new text item into list but here I want to add item only if it's not already present in list.


Thanks in advance

you can loop the list and check if the text is already in the list or not.

Hi Gopal,

You can use ListFilter or ListIndexOf with the desired condition and check if the result is empty or not.

Cheers,

Solution

Hi Gopal,

You can also use the ListIndexOf Action (from System module). It will give you the index of the first that it finds, or -1 if it does not find any.

Cheers,

José

Solution

Barong Bali wrote:

you can loop the list and check if the text is already in the list or not.

Thanks Borong but It will take more time, 

If my list already have 1000 record and I am adding new 100 record then it will take lot of time to execute, If you have another option please share.

Hello Henrique, José

Thank you, Let me try


if you have long list I suggest either to persist it in the database or use the HashTable.

Hi Gopal,

If you are starting your list from scratch and your list is of type Text maybe your best option is to use an HashTable:

https://www.outsystems.com/forge/21/

This is a more efficient solution to large number of records when searching for an item present in a List.

Cheers,

José 

Hi,

ListIndexOf() requires two values, 1) list  2)condition .

for example

My list is "ColorList" and I have text "Blue" which I want to add

I pass ColorList to the list property but what will be the condition? 



Thanks J & Jose,

I am adding it into my knowledge bank :)

Actually my list isn't that much big. ListIndexOf() solved my problem.

Thank you Henrique & Jose



Gopal Jite wrote:

Thanks J & Jose,

I am adding it into my knowledge bank :)

Actually my list isn't that much big. ListIndexOf() solved my problem.

Thank you Henrique & Jose




mark the correct answer then..