duplicated values in a list

duplicated values in a list

  

Hi 

I have a local list with duplicated values. How can I merge same values from a list? The equivalent of SQL for distinct values... thanks.

Jorge Almeida wrote:

Hi 

I have a local list with duplicated values. How can I merge same values from a list? The equivalent of SQL for distinct values... thanks.

Hi Jorge,

Use this extension: https://www.outsystems.com/forge/Component_Details.aspx?ProjectId=22

and Use distinct function

i cannot use extensions. I need a clean and short way to do it without any extensions (no variable locals too). thanks. :)


Jorge Almeida wrote:

i cannot use extensions. I need a clean and short way to do it without any extensions (no variable locals too). thanks. :)



Without local vars maybe you can't do it, you can use some logic by sorting your list and compare if the next value is the same as previous...You can use an hash table too

how to use an hash table? that's maybe ocould help. :)

Hash is not yet a native tool of outsystems, so you can't use, is an extension too :( sorry

Using database is an option but is a very bad option

no... using sql for this case is very bad, indeed.

Solution

Jorge,

Can you explain why you can't use Extensions? They're an integral part of the Platform, and can be used like any other reference.

That said, provided your list is sorted, you can use ListFilter for this purpose. For a condition use something like "List.CurrentRowNumber = 0 or List[List.CurrentRowNumber - 1].Attribute <> Attribute" (where List is your list, and Attribute the Attribute you want to compare).

Solution

yep. Policies of the business. weird, I know. 

list is 

String_Split.List (already sorted)

attribute is

String_Split.List.Current.Text.Value


SyntaxEditor Code Snippet

String_Split.List.CurrentRowNumber = 0 or

(String_Split.List[String_Split.List.CurrentRowNumber - 1] <> String_Split.List.Current.Text.Value)

led to an error in the second OR. where is the error?

Thanks. 

ok. I found the errror:

SyntaxEditor Code Snippet

String_Split.List.CurrentRowNumber = 0 or

(String_Split.List[String_Split.List.CurrentRowNumber - 1].Text.Value <> String_Split.List.Current.Text.Value)


You are amazing Kilian!!!!!! KUDOS!!!!  It worked! :D :D /dancing

Hi Jorge,

I think the problem is that you should use "Text.Value" instead of "String_Split.List.Current.Text.Value", as the Current is already in scope of a ListSort (you can also select it from the tree control of the Expression Editor).

EDIT: Yeah, that too :)

yep. I forgot the .text.value . :D  AND it works like  a gem! :D  

Great to hear Jorge! It's a bit of a hack, but a working hack is better than no hack :). Happy coding :).