Repeat Duplicate Preventer

4647
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
18 Replies
DougBrowning
MVP Esteemed Contributor

You get around this by adding a comma on the search string as well.  Maybe the latest one I did not post.  The latest version did change it a bit.

Do you have it like this  not(contains(${AllPlantsCheck}+",",${Species}+",")))

0 Kudos
NatalieSlayden
New Contributor III

Yes, That is exactly what I have. It works great unless they enter them in out of order. It is throwing me for a loop.

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

 

0 Kudos
DougBrowning
MVP Esteemed Contributor

I retested mine and it works before and after.  Maybe a different 123 version or something else is up.  If you cannot post the form you can dm me it instead.

DougBrowning_0-1669129266284.png

 

0 Kudos
NatalieSlayden
New Contributor III

I DMed you! Thanks so much as always!

0 Kudos
EdmundEkanem1
New Contributor

first time here and I apologise if this has already been treated somewhere else. My ask is, how do I apply this to non-repeats? just a list with options on my form where I do not want an option to be picked more than once? thank you

0 Kudos
DougBrowning
MVP Esteemed Contributor

I am not sure what you mean.  My guess is you have a set of select one questions that all use the same list?

Brute force way would be to check at each question in the constraint

Q1 -> . != Q2 and . != Q3 and . != Q4

Q2 -> . != Q1 and . != Q3 and . != Q4

Q3 -> . != Q1 and . != Q2 and . != Q4

Q4 -> . != Q1 and . != Q2 and . != Q3

You could also try to making a list of all the answers and checking that.  But my fear is that it will add the current question value as you pick it and then the check fails on itself.

QList -> Q1 + " " + Q2 + " " + Q3 + " " + Q4

Q1 -> not(contains(QList, Q1))

Hope that helps

0 Kudos
DustyJordan
Occasional Contributor

Hi @Anonymous User and @DougBrowning,

Thanks for responding!

Doug- I have no doubt you're the one I snagged this method from. Your posts/comments have come up in a lot of my searches for Survey123 solutions over the past few years, and they have been incredibly helpful. 

I was wondering if some kind of update had broken this constraint expression, as I recall doing a lot of testing when I implemented it and don't recall having this issue. I'm going to try your fix and hopefully I can get it working again. I'll let you know if I run into any problems. 

Phil- Thanks for linking that information on calculationModes! I'm going to try Doug's fix of my existing constraint expression first, but if I can't get that to work I'll take a look into calculationModes. I'm always interested in learning a new trick/function in Survey123. 

 

DougBrowning
MVP Esteemed Contributor

Yes 3.14 broke my trick.  It was the 2 in row where it really got tripped up.  The fix listed is working for me but it took a lot of hours to get it.   I did try all the calc modes and it did not work.  I may not have tried every combination but a lot of them - took close to 4 hours to get it!  Hope it works for you.

DustyJordan
Occasional Contributor

Hey Doug,

I just got done implementing your fix just as you instructed, and it worked like a charm. I've done some testing and it triggers off consecutive and non-consecutive duplicates, and allows paging forward/backward through repeats when there are no duplicates detected. 

Thank you very much for sharing this fix!

I said it before, but I'll say it again, you (and this forum in general) have been a great help to me over the past few years as I've learned and continued to build upon my Survey123/XLS skills. The first forms I created are a far cry from the most recent ones I've built.

So thank you for that, it has been greatly appreciated. 

-Dusty