Select to view content in your preferred language

How to not use a list item more than once.

8045
24
Jump to solution
02-27-2019 07:32 AM
DougBrowning
MVP Esteemed Contributor

I have a select one list in a repeat where I want to stop, or warn, a user if they pick an item more than once during the repeats.  This list is about 1,300 items.

I created a field that keeps a running list from my repeat

join(", ", ${SpeciesList})

I tried this constraint on the list  not(contains(${AllPlants}, ${SpeciesList}))  but it always triggers since it is in the list as soon as i pick it.

Is there a way to count the number of string occurrences?  Or remove it from the check somehow.

Thanks for any ideas

Tags (3)
24 Replies
DougBrowning
MVP Esteemed Contributor

No this would be a limitation.  If they go back and start editing previous repeats all kinds of stuff would probably break in my form.  We tell the crews if they mess up a plant just delete that repeat and add a new one at the end.  Then we are ok.  The workflow is just them walking around and log what plants they see.  So no real reason to go back through the list.

0 Kudos
AndreaBaquerizo
New Contributor

Hi @AndrewPadilla , 

I have tried to use the javascript code in a myFunctions.js' 

function HasDups (myArray){

return new Set(myArray).size !== myArray.length;

}

but I have a error in the script called "Expected token ;"  If you know what the error is, could you tell me a solution

Thanks 

0 Kudos
AndrewPadilla
Frequent Contributor

Hi @AndreaBaquerizo,

I am not an expert in writing JavaScript but it looks like you have the formula correct as pasted above but the screen shot you attached does not match. You need to remove the space between "(myArray)" and ".size", and also add a space between ".size" and "!" (see attachment). Easiest way would be to copy and paste the original formula. I attached a screen shot of my .js file. I hope that helps.

 

0 Kudos
ChrisRoberts2
Frequent Contributor

The JS fuction works great it my dev version of my survey, but as the production version will be a public survey I just realised its not going to work!  Is there another way to achieve the same result?  Within the repeat the user has a list of 12 target speices to survey and count, I dont wan them counting the same species twice as a seperate record.

Cheers

Chris

0 Kudos
CSR_GarinHirata
Emerging Contributor

@DougBrowning I had a question about your way of checking for duplicates. Does it work in the Survey123 Web app? I have something working in the mobile app version, but it doesn't work in the web app survey. I am not using a javascript file. Any Thoughts? Thanks!

0 Kudos
DougBrowning
MVP Esteemed Contributor

I would think it would work.  I do not use the web much.  One common gottcha in the web is + does not work to combine strings.  You have to use concat().   Best thing is to post the form.

0 Kudos
CSR_GarinHirata
Emerging Contributor

I highlighted the repeat section in the excel spreadsheet. Thanks for taking a look. 

0 Kudos
DougBrowning
MVP Esteemed Contributor

I see it works in Connect fine

DougBrowning_0-1639005926892.png

 

Sorry I have no idea on the web.  I do not see anything but I never use the web forms so I really do not know.  Maybe someone else will.  Sorry

Oh wait I see you are using reserved words. These little green boxes mean not cool.   Could be it.

DougBrowning_1-1639006052658.png

 

DougBrowning_2-1639006072545.png

Also not sure you can start a field with a special char.  Prob not

_size

Hope that does it

0 Kudos
CSR_GarinHirata
Emerging Contributor

I made some of those changes, but with no luck. Thanks for all your help. I might have to make a call into esri support to see what might be wrong. 

 

Thanks again, 

GH

0 Kudos
DougBrowning
MVP Esteemed Contributor

Did you publish it as a all new layer?  If not those fields would still be in the service and could still cause issues.  Its worth a shot.

0 Kudos