Repeat Duplicate Preventer

4146
18
Jump to solution
03-21-2022 11:36 PM
DustyJordan
Occasional Contributor

First, a little background. I have a workflow that involves going out and servicing a series of assets on a weekly basis. Each asset has a unique barcode/ID that the user scans or manually enters into Survey123, along with a series of other questions. Upon reviewing the data for reporting I noticed a hair pulling amount of errors, one of which was people entering data for a particular asset more than once. Apparently my techs don't like scanning barcodes and prefer to just enter things manually.

At that point I decided I would just design a better form that made it nearly impossible for my users to submit erroneous records.

Enter the duplicate checker. I admittedly do not have the skills to come up with something like this from scratch, so naturally I pilfered it from another Survey123 user after some GoogleFu. From my understanding, I'm basically using a join in the calculation field to populate a list of barcodes/IDs. Then, I have an expression in the constraint field to check and make sure each additional repeat (i.e. Barcode/ID) does not already exist in the join list.

Here is the constraint expression:

not(contains(substr(${Tubes_Serviced}, 0, string-length(${Tubes_Serviced}) - 3), ${Barcode}))

The issue I'm experiencing now is that if the user enters a duplicate and somehow navigates backwards in the repeat section before immediately deleting it, they get locked in place. The duplicate checker kicks in triggers off the currently displayed repeat, which prevents them from navigating forward, unless they delete the current record. 

I'm wondering if there is a way to modify this expression to prevent this lockout that happens when navigating to/from duplicate repeat records?

Thanks for reading!

-Dusty

P.S. I've attached my xlsx form if it helps getting the whole picture.

P.S.S. I've also learned that it seems no matter what you do, errors will find a way.

0 Kudos
1 Solution

Accepted Solutions
DougBrowning
MVP Esteemed Contributor

It looks like you are using my trick.  It broke on me also.  Took about 4 hours but I got it fixed using once() around the join.  Join seems to be a bit funky now and I am working on it with Phil here https://community.esri.com/t5/arcgis-survey123-questions/once-join-work-differently-on-the-first-rep...

I tried to change your form but then I would have to use a barcode.  Hopefully you can follow this.  The pain was 2 in a row was not caught at first.  Test 2 in a row but also a later dup.

On line 56 add a once - once(join(",",${Barcode}))

Under (must be under) the line with the join add 2 temp fields.  One a calc of 1 and one that counts this field. Like this

DougBrowning_0-1647959149173.png

 

Then change your constraint to Species list = barcode and AllPlants = TubesServiced

if(${TempCount}=0, 1,${SpeciesList}='' or not(contains(${AllPlantsCheck}+",",${SpeciesList}+",")))

Note not sure if you need the commas part but we had issues where ABCD was found as a dup of ABCD3.

I hope that makes sense it was not easy.

Your other option is javascript.  Look for my post with the code.  Hope this helps.

View solution in original post

18 Replies
by Anonymous User
Not applicable

Hi @DustyJordan,

What you are seeing sounds as though it would be expected, as when you navigate backwards you are now re-evaluating those values in the previous repeat, meaning the answers in them may now not be valid as the string contains the value you are trying to stop being entered.

With the 3.14 release we introduced calculationModes, have you tried this new parameter out:

https://doc.arcgis.com/en/survey123/desktop/create-surveys/prepopulateanswers.htm#ESRI_SECTION1_FC29...

https://www.esri.com/arcgis-blog/products/survey123/announcements/whats-new-in-arcgis-survey123-febr...

By using one of these modes and combing with the position() function, you should be able to count the repeat record you are on, and the position, compare them, and work out of the calculation should be run again. May need some trial and error, but should be possible to get it working the way you want.

Regards,

Phil.

0 Kudos
DougBrowning
MVP Esteemed Contributor

It looks like you are using my trick.  It broke on me also.  Took about 4 hours but I got it fixed using once() around the join.  Join seems to be a bit funky now and I am working on it with Phil here https://community.esri.com/t5/arcgis-survey123-questions/once-join-work-differently-on-the-first-rep...

I tried to change your form but then I would have to use a barcode.  Hopefully you can follow this.  The pain was 2 in a row was not caught at first.  Test 2 in a row but also a later dup.

On line 56 add a once - once(join(",",${Barcode}))

Under (must be under) the line with the join add 2 temp fields.  One a calc of 1 and one that counts this field. Like this

DougBrowning_0-1647959149173.png

 

Then change your constraint to Species list = barcode and AllPlants = TubesServiced

if(${TempCount}=0, 1,${SpeciesList}='' or not(contains(${AllPlantsCheck}+",",${SpeciesList}+",")))

Note not sure if you need the commas part but we had issues where ABCD was found as a dup of ABCD3.

I hope that makes sense it was not easy.

Your other option is javascript.  Look for my post with the code.  Hope this helps.

NatalieSlayden
New Contributor III

@DougBrowning  Would you mind taking a look at my form? When I select my first grid structure in my repeat, It is notifying that I have already selected it. I know you mentioned you had this problem as well but I am struggling to solve it. The main xls form is the CopyCoral Nursery Monitoring Form. Thanks in advance. You have been solving so many of my issues recently! 

0 Kudos
DougBrowning
MVP Esteemed Contributor

All I had to do was change the calc for line 61.  It should be a count not a join.   once(count(${TempCheck}))

Try that it works for me.  Again this is weird due to the new 123 treating the first repeat different than the rest.  I reported this but they do not think it is a bug.  Sure seems like one to me.

NatalieSlayden
New Contributor III

Thanks @DougBrowning That solved my issue perfectly! Really appreciate it!

NatalieSlayden
New Contributor III

@DougBrowning  So that did work but upon testing I noticed in my feature service that my repeat is now creating a 1st blank entry before they add the first repeat So it will be blank entry (see image), then Grid B1 (1st repeat), B2 (+ repeat), B3 & send. Any idea what could be goin on here? Thanks again!

NatalieSlayden_0-1667415880381.png

 

0 Kudos
DougBrowning
MVP Esteemed Contributor

I have seen it creating blank records at times.  Mostly it was using hidden and I think the appearance of minimal or some combo.  Its been so long I am forgetting what we tracked it down to.  We never did get rid of them though.  I do not think it is the dups code I think it is something else.  Mess with minimal so that you see a + sign vs it auto loading the first record and see if that does it.  If you are using the esri visible try a change to relevant.

Hope that works

NatalieSlayden
New Contributor III

I am going to give some things a try. I think you are totally right tho, not necessarily the dup code. Looks like a bug that has been around for awhile after further research. Thanks as always! Your responses are always so helpful! 

 

NatalieSlayden
New Contributor III

Hi @DougBrowning, Did you ever have issues with someone entering ABCD3 first and then when they went to add ABCD it flagged as a duplicate? The commas are necessary like you said because if they enter it in the correct order of ABCD and then ABCD3, then it does not flag a duplicate but if it is the other way around, it flags. Just wanted to see if you had this occur with you. I have been playing with the code, but have not found a solution yet

0 Kudos