Scan feature service to see if email has already been used?

02-13-2023 12:23 PM
Occasional Contributor III

Posting to see if a workflow is possible, or if any out there have made it work:

I want to ensure that my survey prevents repeat submissions of a particular attribute. An example would be an email - if somebody enters their email and they've already submitted that email, it could produce a warning saying "You've already submitted. Try a different email." and prevent submission. In my case I will have a drop-down list of groups (say Group 1, Group 2.....Group 10). And I only want to accept one survey from each group. So if Group 1 is chosen in the drop-down, but has already been chosen, I want a warning to pop up and prevent submission. 

Poking around it looks like the search() appearance could be used to make this happen: specify the URL of the feature service, the field that contains the group information, and, likely incorporating a hidden field not in the feature service, constrain entries to 'if group is found in list of groups, deny submission.'

Anybody out there done this? Are there pre-established workflows?

0 Kudos
1 Reply
Esri Regular Contributor

Hello @SFM_TravisBott

You can use pulldata('@layer') for this workflow. You would have a select_one question with your groups then pass the selected group in the where clause of the pulldata('@layer') syntax to see if a record already exists with that group. If it does use a constraint to return an error, otherwise if it doesn't your constraint won't run and the user will be good to submit. 

Please see the Query a Feature Layer sample in Survey123 Connect for some examples that use pullata('@layer'). The sample doesn't show this exact use case but can be derived from the sample. 

I would suggest returning the objectId field as the check for existence or not, the syntax would be something like: 

pulldata("@layer", "getValue", "results.objectId", "<Feature Service URL>, concat("group='", ${group}, "'"))

Your constraint could then be something like string-length(${query})<1

Thank you,
0 Kudos