22
Views
5
Comments
Solved
Select Distinct from a list (not an entity)
Question
Application Type
Reactive

Hello,

I need to validate if there are diferent values in a field of a list.

For example, I have a list with user and company and I want to validate that all the users of the list are from the same company (I need to validate that there is only one company).

To do it on a SQL query is easy, i can make a count distinct over the company field (and validate if it is gretaer than one) but i do not know how to do it with a list.

Can anybody help me?

Thank you very much!




Rank: #56
Solution

Hi Salvador Duran,


You can use ListDistinct action from System and check afterwards if the output DistinctList length is equal to your initial list. If they are, that means that there were no distinct records; otherwise it means there were.



Hope it helps.


Kind Regards,
João

Rank: #541
Solution

Hi Salvador,

In addition to João Marques' reply, another way to achieve this is using the ListAll action.

In the example, I assume that you don't know what is the Company, so, I get the name of the first user's company and set a variable with it. Then, To ListAll, I pass the entire List and the condition "User.Company.Name = FirstCompanyName". If ListAll.Result is false, means that there is at least one User from a different Company.

Best regards.

Rank: #297
Solution

Hi Salvador

Both João and Kadu's reply is great.

In addition to João Marques' reply,  If you want to use ListDistinct action, Then you need to map the list to another list that only has the company attribute.

If you want to adopt Kadu's solution, Then instead of use ListAppendAll, I recommended use ListFilter.


Kind Regards,

Rank: #297

Sorry, The second image's condition was wrong. 

Should be Company, not User.

Company <> ListUser.Current.Company


Rank: #5062

Thank you very much to everybody. Problem solved!

Rank: #56
Solution

Hi Salvador Duran,


You can use ListDistinct action from System and check afterwards if the output DistinctList length is equal to your initial list. If they are, that means that there were no distinct records; otherwise it means there were.



Hope it helps.


Kind Regards,
João

Rank: #541
Solution

Hi Salvador,

In addition to João Marques' reply, another way to achieve this is using the ListAll action.

In the example, I assume that you don't know what is the Company, so, I get the name of the first user's company and set a variable with it. Then, To ListAll, I pass the entire List and the condition "User.Company.Name = FirstCompanyName". If ListAll.Result is false, means that there is at least one User from a different Company.

Best regards.

Rank: #297
Solution

Hi Salvador

Both João and Kadu's reply is great.

In addition to João Marques' reply,  If you want to use ListDistinct action, Then you need to map the list to another list that only has the company attribute.

If you want to adopt Kadu's solution, Then instead of use ListAppendAll, I recommended use ListFilter.


Kind Regards,

Rank: #297

Sorry, The second image's condition was wrong. 

Should be Company, not User.

Company <> ListUser.Current.Company


Rank: #5062

Thank you very much to everybody. Problem solved!