Method to exclude duplicate values in repeat fields

06-19-2017 09:12 AM
Status: Open
New Contributor III

I have a Select_One field in a Repeat group and I would like to be able to prevent users from selecting the same answer twice in different instances of the Repeat. Specifically, it is a plant species list, and once a user has entered details (area covered) for a particular plant species, accidentally entering it twice would mess up the calculated results (total plant coverage). There may be multiple ways to achieve this, but I would imagine the easiest might be an expression in the Constraint column that either requires a Unique response or excludes a Duplicate response in that particular field. Another option might be to create a type of Select list that removes answers as they are selected, but the Constraint option would likely be more versatile, as it could by applied to Text and other types fields as well.


Hi Camille...

I like your idea.... it would make plant species data collection easier for I too.... \

A possible solution to your problem and mine.... would be to make it possible to restrict duplicates and copy the plant names from the repeat before into the next repeat.... 

Referencing each plant by position within each repeat has the potential to identify if there are duplicates within your repeats....

Thanks for submitting your idea!

I was able to apply a constrain to the select-on field using a constrain with the following steps:

1.- Calculate a join of the field: ej join('',${fieldselectone})

2.- Calculate isrepeated field inside the repeat using a regular expression: regex(join('',${fieldselectone}),concat('^[0-9]*(',${fieldselectone},')[0-9]*(',${fieldselectone},')[0-9]*$'))

Just note I'm using numbers [0-9] as the character set because on my case the ${fieldselectone} is a numeric code list, you could replace this wit [A-Z] or [A-Z0-9] for alpha

3.- Apply the isRepeated field as constrain on the ${fieldselectone}. Ej not(boolean-from-string(${isRepeated}))

I hope it works for you.


Daniel R.

I was doing this before I found this post.  Issue is that the item gets added to the check list immediately - which then throws an error.

So what I did is take the last few chars off the join list and check that.  Works great until you go backwards a few repeats and try to change the value.

I wish there was a strcount to count how many are found.