Constraint duplicate answers in repeat group

Hi,

I have an issue which seems to appear only on ODK collect (v2021.2.4) and not on enketo.

I'm trying to add a constraint for row 27 (name: S1a) to check for duplicate entries.

For example, if you've already entered the initials as "AA", should not be allowed to enter the same initials (duplicate answer). It works perfectly during data entry but the form cannot save and exit if marked as finalized, it brings me back to the second repeated group and tells me that the answer (name: S1a) is invalid, I can't see where I have gone wrong. Please see the calculations highlighted in yellow.

Is it possible to check for duplicate answers for text type OR did I missed something?

Thank you for your help.

Hi @Chonticha
Could you attach your xls form so that we can test it?

I believe the problem appears because values don't get updated when you expect. show_member contains a list of all member names. It gets updated after a member is added, but before that member's constraint is checked. However, at the end, all members are present in show_member. At this point, the constraint check runs again and finds that the current member is present in show_member, and so the constraint fails.

We had similar issues at various points; they are tricky because it's a bit unpredictable at what point values get updated. From memory, here is how we solved it at the time:

Don't use a constraint in the question. Instead, add something like this right after the question:

type: note
label: You've entered a duplicate name; please go back and fix.
required: yes (this prevents the user from continuing, since a required note cannot be skipped)
relevant: (here you need to check whether the current name appears *twice* in the list)

For the check, we've used something like this: contains(substring-after(${all_members}, ${member}), ${member}). The substring-after filters out the first occurrence, and the contains detects the second.

Hope this helps!