17
Views
2
Comments
Solved
How to find and return duplicate value in record list
Application Type
Traditional Web
Service Studio Version
11.6.30 (Build 11706)

The application I'm working on receives a message which is deserialized into a structure, this structure contains some record lists.

I'm validating a list for any duplicate values, the business rule is that a certain attribute has to be unique. I want to raise an exception, naming the value of this attribute when it is not unique in the structure list. 

To be clear, I'm not interested in removing the duplicates from the list using ListDistinct, I specifically need the value that is a duplicate (or multiple values if there are multiple values that are not unique)

I was thinking of sorting the list by this text attribute and in a for each loop where I already have other validations on every record, I could check if the current value is equal to that of the previous record. I'm wondering if this is the most elegant way to solve this.

Solution

Hi Fred,

Yes you can sort the list by attribute and simply check current with previous record.


Regards

Shashikant Shukla

mvp_badge
MVP
Rank: #2

Hi Fred,

If you're already looping over the list, this seems indeed the best way to handle it. Just assign the current values at the end of all checks, and in the next iteration compare those values with the then-current ones to see if there are duplicates.