# Avoid Duplicate Barcode Scan in Subsequent Repeat Groups

**URL:** <https://forum.getodk.org/t/avoid-duplicate-barcode-scan-in-subsequent-repeat-groups/55990>\
**Category:** Support\
**Tags:** form-design, odk-xlsform\
**Created:** [July 29, 2025, 4:17pm UTC](https://forum.getodk.org/t/avoid-duplicate-barcode-scan-in-subsequent-repeat-groups/55990 "2025-07-29T16:17:44Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tyler\_Depke](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/tyler_depke/32/17598_2.png) [@Tyler\_Depke](https://forum.getodk.org/u/Tyler_Depke)\
**Post date:** [July 29, 2025, 4:17pm UTC](https://forum.getodk.org/t/avoid-duplicate-barcode-scan-in-subsequent-repeat-groups/55990/1 "2025-07-29T16:17:44Z")

</div>

**1. What is the issue? Please be detailed.**  
The context is I'm propagating plants and I have tags with barcodes like G0001-G9999 that I'm putting on each plant as we graft/propagate and in the case of a single submission all the repeats are coming from the same source but going onto different new plants, but I want to make sure that as new tags are being put on plants, that tags do not get scanned twice to avoid duplicate scans and skipping one. In the case where you know you have 10 plants, you scan one twice and the rest 9 times, it would still give you a total of 10, but one of your tags wouldn't be scanned and. Its critical in this step as we label plants that each new tag is scanned once.

I have a repeat group with the first question as a barcode scan and I want to make sure that all subsequent barcode scans are not duplicated. My first thought would be to put a constraint. My current constraint for that barcode field is

`regex(., '^[\*GCASTR][0-9]{1,4}(-[0-9A-Z]{1,4})?$')`

How would you either modify this constraint or add other calculate fields to accomplish this so that 2nd repeat and beyond wouldn't allow you to proceed if that barcode had already been scanned?

**2. What steps can we take to reproduce this issue?**

**3. What have you tried to fix the issue?**  
This simple [example](https://docs.google.com/spreadsheets/d/1CyctxQsUNuxWYjhHqlCgo32HRGnIf1PH-z-xUo_HP2k/edit?gid=0#gid=0) I saw to avoid duplicates selects in repeat group posted by @LN, but I don't think this would work here because the selected() function only applies to selects. This looks like it would be close, but would maybe need to change constraint function selected() to contains() ? Would anything else need to be changed? In my case since I already have a constraint for the barcode would I have to do something like:

`and(regex(., '^[\*GCASTR][0-9]{1,4}(-[0-9A-Z]{1,4})?$'), not(contains(${so_far}, .))) `

---

<div class="post-metadata">

**Author:** ![mathieubossaert](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/mathieubossaert/32/6131_2.png) [@mathieubossaert](https://forum.getodk.org/u/mathieubossaert)\
**Post date:** [July 30, 2025, 4:50am UTC](https://forum.getodk.org/t/avoid-duplicate-barcode-scan-in-subsequent-repeat-groups/55990/2 "2025-07-30T04:50:11Z")

</div>

> [@Tyler\_Depke](#):
>
> but I don't think this would work here because the selected() function only applies to selects

Hi Tyler, in fact the selected() function checks if the value of the question is in a space separated list of values, as a select\_multiple question produces.  
You can use the [join()](https://docs.getodk.org/form-operators-functions/#join) function to aggregate the barcode values from the repeat to avoid the new one to be input twice (not selected).  
If you change the question type in @LN 's example from select\_one to text it will work fine.

---

<div class="post-metadata">

**Author:** ![Emalee\_Martin](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/emalee_martin/32/27055_2.png) [@Emalee\_Martin](https://forum.getodk.org/u/Emalee_Martin)\
**Post date:** [January 13, 2026, 3:17pm UTC](https://forum.getodk.org/t/avoid-duplicate-barcode-scan-in-subsequent-repeat-groups/55990/3 "2026-01-13T15:17:28Z")

</div>

Hi! I am trying to do something similar - only difference is that my barcode can be scanned _ **or** _ manually entered. The logic works when entering data on my phone, however when I go to submit the form it flags every barcode as a duplicate/already entered. What am I doing wrong?

[avoid\_dups\_in\_repeat\_groups.xlsx](https://forum.getodk.org/uploads/short-url/qzFEJ37gVf8lNPV7eDsnrDsZ9BH.xlsx) (222.8 KB)

---

<div class="post-metadata">

**Author:** ![Tyler\_Depke](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/tyler_depke/32/17598_2.png) [@Tyler\_Depke](https://forum.getodk.org/u/Tyler_Depke)\
**Post date:** [January 13, 2026, 4:57pm UTC](https://forum.getodk.org/t/avoid-duplicate-barcode-scan-in-subsequent-repeat-groups/55990/4 "2026-01-13T16:57:18Z")

</div>

> [@Emalee\_Martin](#):
>
> The logic works when entering data on my phone, however when I go to submit the form it flags every barcode as a duplicate/already entered.

Can you be more specific? From what it sounds like you can create another repeat without the constraint triggering/preventing you from proceeding?

If this is the case, then your field `not(selected(${so_far}, ${barcode}))` is not correct. I would add a note or two just above the `barcodescan` row to debug. Just put ${so\_far} in the label and ${barcode} in the other note label to see what is coming up to verify everything looks right for each of those variables.

---

<div class="post-metadata">

**Author:** ![Emalee\_Martin](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/emalee_martin/32/27055_2.png) [@Emalee\_Martin](https://forum.getodk.org/u/Emalee_Martin)\
**Post date:** [January 13, 2026, 7:23pm UTC](https://forum.getodk.org/t/avoid-duplicate-barcode-scan-in-subsequent-repeat-groups/55990/5 "2026-01-13T19:23:00Z")

</div>

The logic works correctly during data entry (meaning unique IDs are accepted and duplicate entries are flagged/I’m unable to proceed). However, upon submitting the form, I receive an error and the system treats all barcode entries as duplicates, even when none exist.

I accidentally uploaded the wrong file earlier—I've updated my original message and reattached the correct file below.

[avoid\_dups\_in\_repeat\_groups.xlsx](https://forum.getodk.org/uploads/short-url/qzFEJ37gVf8lNPV7eDsnrDsZ9BH.xlsx) (222.8 KB)

---

<div class="post-metadata">

**Author:** ![Emalee\_Martin](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/emalee_martin/32/27055_2.png) [@Emalee\_Martin](https://forum.getodk.org/u/Emalee_Martin)\
**Post date:** [January 13, 2026, 9:02pm UTC](https://forum.getodk.org/t/avoid-duplicate-barcode-scan-in-subsequent-repeat-groups/55990/7 "2026-01-13T21:02:03Z")

</div>

Resolved! Attaching the file that works

[avoid\_dups\_in\_repeat\_groups.xlsx](https://forum.getodk.org/uploads/short-url/3KmK3j0gfWTR3Td1LSjhWwiJvWY.xlsx) (223.2 KB)

---

<div class="post-metadata">

**Author:** ![Tyler\_Depke](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/tyler_depke/32/17598_2.png) [@Tyler\_Depke](https://forum.getodk.org/u/Tyler_Depke)\
**Post date:** [January 13, 2026, 9:06pm UTC](https://forum.getodk.org/t/avoid-duplicate-barcode-scan-in-subsequent-repeat-groups/55990/8 "2026-01-13T21:06:09Z")

</div>

replace `if(${barcodeentry} = 1, ${barcodescan}, ${barcodemanual})` with

```auto
if(${barcodeentry} = '1', ${barcodescan}, ${barcodemanual})

```

and see if that works. I think 1 is a string for the select question whereas the logic is treating it as an integer...
