Referencing previous iterations of current repeat group in order to detect duplicates

I have a form containing a repeat group. Inside the group I collect a number (actually by scanning a barcode). I want to check that the "current" number is not the same as any previous number collected within this repeat group (within the current form instance). Is there any way to do this?

The relevant parts of my instance definition are...


<id_women jr:template="">
<mw_wg_barcode id="mw_wg_barcode" />

</id_women>

count1 is a calculate field where (for now) I'm just trying to count the number of barcodes scanned, with expressions like
count(/TestCounts/[@id='mw_wg_barcode'])
(hacked from the solution to another problem), or
count(/TestCounts/id_women/
[@id='mw_wg_barcode'])
But both these cause ODK Collect (1.4 - 1038) to crash at the beginning of the repeat (my plan was, once this worked, to change the count so it was filtered on previous values equal to the current value).

Any ideas?

Thanks.

In case it's of interest to anyone else, I found a solution (see attached .xlsx).

This works by concatenating the ID numbers (which in my example are always 3 digits long), separated and surrounded by spaces, outside the repeat, and then using a regular expression to locate multiple occurrence of the "current" ID number in the concatenated string. Because of the order in which ODK Collect does things, it's not possible to trap duplicates using this technique in a constraint on the ID field itself, but I can trap them at the next question within the repeat loop.

Test.xlsx (13.6 KB)

··· On Tuesday, October 29, 2013 7:36:49 AM UTC, james.b...@gmail.com wrote: > I have a form containing a repeat group. Inside the group I collect a number (actually by scanning a barcode). I want to check that the "current" number is not the same as any previous number collected within this repeat group (within the current form instance). Is there any way to do this? > > The relevant parts of my instance definition are... > > > > > > > > > > count1 is a calculate field where (for now) I'm just trying to count the number of barcodes scanned, with expressions like > count(/TestCounts/*[@id='mw_wg_barcode']) > (hacked from the solution to another problem), or > count(/TestCounts/id_women/*[@id='mw_wg_barcode']) > But both these cause ODK Collect (1.4 - 1038) to crash at the beginning of the repeat (my plan was, once this worked, to change the count so it was filtered on previous values equal to the current value). > > Any ideas? > > Thanks.

Attached another way to check for duplicate

CheckForDuplicate.xls (26.5 KB)

··· On Tuesday, 29 October 2013 10:36:49 UTC+3, james.b...@gmail.com wrote: > > I have a form containing a repeat group. Inside the group I collect a > number (actually by scanning a barcode). I want to check that the "current" > number is not the same as any previous number collected within this repeat > group (within the current form instance). Is there any way to do this? > > The relevant parts of my instance definition are... > > > > > > > > > > count1 is a calculate field where (for now) I'm just trying to count the > number of barcodes scanned, with expressions like > count(/TestCounts/*[@id='mw_wg_barcode']) > (hacked from the solution to another problem), or > count(/TestCounts/id_women/*[@id='mw_wg_barcode']) > But both these cause ODK Collect (1.4 - 1038) to crash at the beginning of > the repeat (my plan was, once this worked, to change the count so it was > filtered on previous values equal to the current value). > > Any ideas? > > Thanks. > >

I love it! This solution looks really useful to me.

··· On Fri, Nov 8, 2013 at 3:08 AM, wrote:

On Tuesday, October 29, 2013 7:36:49 AM UTC, james.b...@gmail.com wrote:

I have a form containing a repeat group. Inside the group I collect a
number (actually by scanning a barcode). I want to check that the "current"
number is not the same as any previous number collected within this repeat
group (within the current form instance). Is there any way to do this?

The relevant parts of my instance definition are...


<id_women jr:template="">
<mw_wg_barcode id="mw_wg_barcode" />

</id_women>

count1 is a calculate field where (for now) I'm just trying to count the
number of barcodes scanned, with expressions like
count(/TestCounts/[@id='mw_wg_barcode'])
(hacked from the solution to another problem), or
count(/TestCounts/id_women/
[@id='mw_wg_barcode'])
But both these cause ODK Collect (1.4 - 1038) to crash at the beginning
of the repeat (my plan was, once this worked, to change the count so it was
filtered on previous values equal to the current value).

Any ideas?

Thanks.

In case it's of interest to anyone else, I found a solution (see attached
.xlsx).

This works by concatenating the ID numbers (which in my example are always
3 digits long), separated and surrounded by spaces, outside the repeat, and
then using a regular expression to locate multiple occurrence of the
"current" ID number in the concatenated string. Because of the order in
which ODK Collect does things, it's not possible to trap duplicates using
this technique in a constraint on the ID field itself, but I can trap them
at the next question within the repeat loop.

--

Post: opendatakit@googlegroups.com
Unsubscribe: opendatakit+unsubscribe@googlegroups.com
Options: http://groups.google.com/group/opendatakit?hl=en


You received this message because you are subscribed to the Google Groups
"ODK Community" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to opendatakit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--

Smap Consulting http://smap.com.au/| Mobile Data Collection Solutions
Application Developer - neilpenman@gmail.com minqiang.huang@gmail.com
Twitter: @dgmsot
Skype: ianaf4you
Phone: +61 402 975 959
Blog: http://blog.smap.com.au http://smap.com.au/blog

James, how are you?

I don't know much about computing so I use XLSForms to make my researches.

I am having a trouble exactly the same manner as you, as I am having forms
with repeated numbers, which could not happen.

I don't know what I did wrong but I was able to input the same number (112)
in your test form anytime I wanted, without any question. I don't know if
anyone has changed your formula, as it is shared on Google Drive.

Could you please help me with that?

Thank you very much indeed.

Rubem Dornas.

Hi everyone,

I wanted the same thing that to prevent scanning same QRCode in the repeat
group, and I tried with the attached "CheckForDuplicae.xls". It's worked a
bit but creates problem during review the form (using ODK collect 1.4.4),
it treats every unique input as a repeat and start constraining from the
very first input and it requires to scan a new QRCode which is not expected.

Even with "ODK collect 1.4.7 rev 1053" can't save the form.

So, could anyone of you please suggest any solution of it? Thanks in
advance.

Marshal

··· >

Apologies. I have only just seen your post from last November.

I think my example does work, but only if the form is called Test. This because in cell H6 of my spreadsheet, I have used an explicit reference to the id number field within the repeat. I should instead have written:
concat(' ',join(' ',${mwid}),' ')

But, I have since discovered a limitation with this technique, at least using the 1.4 (1038) client. ODK will crash if the concatenated string exceeds a certain length (that is, if there are many iterations of the repeat group).

Hi @James_Beard_Tz

Thank you for sharing the test file, in this while reading barcodes the test file is not working properly. Please suggest to us how to avoid duplicates while reading bar or QR codes.