Good day. I have created a survey123 to capture projects with Unique numbers and i would like to find out how to add a unique constraint to a field to avoid duplicates entries?
Best regards
This works for hosted feature layers:
https://doc.arcgis.com/en/arcgis-online/manage-data/add-unique-constraint.htm
I do not think this is possible as Survey123 is primarily designed to work offline; it won't check if the same unique value has been entered on a draft survey still offline on another device. You would get an error on submission when the feature edit is applied and the unique field constraint is encountered.
You could rely on the GlobalID which is created after submission. You could also create a hidden string to randomly generate an ID value. Some discussion on that here:
You could then use these IDs, editor tracking properties, date fields etc to create the unique IDs on the service after submission
Thank you so much for the insight and its much appreciated.
Glad to hear!
If it's useful please give kudos.
If it's the answer, please mark as such. You can wait to see if others want to comment.
Thanks.
Hi. To add to @magisian 's answer:
This blog post describes some techniques to create unique values. It may help.
If you survey is meant to work online, you can also use a custom JS function to query your survey layer and figure out if there is already a record with the same project number. The code is here:
https://github.com/IsmaelInRedlands/Survey123-Tricks-of-the-Trade/blob/main/getRecord
The custom JS function would be ideal for your constraint (again, for online workflows only).
For details on using custom JS functions, check this blog. Be aware that using custom JS functions is not allowed in public surveys. We plan to include the getRecord JS function above as a built-in function within Survey123 later this year. This will allow you to use this type of query in public surveys without the custom JS function limitations.