Preventing duplicate entries in a repeat loop

Hi, I am trying to collect the ID of participants within a household that have now moved house.
I have the following so far:
Q1. How many household members have moved since last contact?
Then a repeat loop with repeat_count set to be the answer to Q1 containing the question:
Q2. Please enter the ID of the household member(s) that have moved

Is it possible to prevent the same participant ID being entered more than once (ie duplicate answers to Q2)?

Welcome to the community, @saspackman! Is the household member you aim to be a finite number or an infinite number?

Hi, thanks for looking at my question!

I have not put any constraints on Q1 yet, but I will need to, so it will be a finite number if I have understood correctly.

@saspackman, maybe you could do it as outlined in the image shared below:

In the survey tab of your xlsform:

Data entry screen as seen in Enketo: when the same id is entered twice

Data entry screen as seen in Enketo: when a unique id is entered

Reference xlsform:

Restrict IDs already selected from a repeat group.xlsx (10.0 KB)

1 Like

How do we make this method work for the mobile version…It only works on Enketo.

It keep throwing error…
Xpath evaluation:type mismatch
The second parameter to be the selected() function must be in quotes(like ‘1’)

Please i need a work around to this problem

Thank you

@chiabotu, could you share with the community a screenshot of the same you are seeing? Did you try the xlsform that was shared with the community?

https://community.kobotoolbox.org/uploads/short-url/doI2BkYrmoW1Py83asMJl10kGez.xlsx

Thesame challenge was posted here…buh i wanted it to work on the mobile device. It only works for enketo.

Yes…i used the form that was shared with the community…Making it work on kobocollect is imposible…saying

Xpath evaluation:type mismatch
The second parameter to be the selected() function must be in quotes(like ‘1’)

The idea here is to prevent duplicate copy of same data in thesame project before submission.
How to make it work on kobocollect app is the issue.

Thank you

Dear @Kal_Lam ,
your method would be good but when you try to add more than 2 identification numbers and try to validate/send the form it returns an error. The same applies to your solution here: Restrict choices already selected from a repeat group - #2 by Kal_Lam
Could you take a look into this? Thanks :slight_smile:

You could try with this validation logic, it works for more than 2 items:

2 Likes

Thanks @francisco.r this adjusted substring-after calc fixed the issue for us. Our form, which collects scanned QR codes to record class attendance, no longer allows duplicates (a common error). The previous example was possibly designed for a set of choices(?) and would only accept the first and last entries in the repeat loop upon validation.

2 Likes

Hello @chiabotu i have the same issue and error message, did you managed to found a solution for the kobo collect app?

Thank you, @francisco.r for updating the syntax. This update has benefitted the entire community! Expecting the same support in the upcoming days too.

Here is the sample updated XLSForm for reference anyone willing to test this approach:

Restrict IDs already selected from a repeat group.xlsx (10.1 KB)

1 Like

I tried to use the above attached form; works and validate on enketo but give an error on KoboCollect

This is the best working and simple solution

Credit: Hélène Martin on odk forum

Example has been put for both integer and select one questions in repeat loop

I hope this will help the community😃
No duplicates in repeats.xlsx (12.9 KB)

1 Like

Thanks for this. It worked perfectly as I had wanted.