I would like to set up a constraint for a field that validates whether the value entered exists in a specific field within a separate ArcGIS Online feature class.
I am using the latest Survey123 Connect in ArcGIS online. The end users will be using a web form to fill this out.
Use case:
We require users to enter their license number as a mandatory field. We intentionally do not want to use a dropdown menu to avoid the risk of users selecting the wrong license or using someone else's license if they don’t have one.
Instead, once the user manually enters their license number, we want to validate that input against a field in a AGOL feature class to ensure it exists in the dataset.
This validation dataset is accessible to all users who will be filling out the survey.
let me know if anyone has done something like this or if this is possible.
Thanks!
Solved! Go to Solution.
hmmm, So I recreated this with sample data and the workflow does work. And it appears from your test that your feature layer is queryable, so I am guessing that it is just a syntax error.
From here I would work backward, and start with hard coding your where clause ensuring you get something that works and once you have it working with a static url, move that syntax for the where clause to the helper question with the dynamic field as above.
pulldata("@layer","getValue", "attributes.CONTRACTNO","https://services.arcgis.com/xyzxyzxy/arcgis/rest/services/EXAMPLELicenses/FeatureServer/0", "CONTRACTNO=xyzxyzx")
or 'CONTRACTNO="xyzxyzx"' trying various syntax until you get it to return the correct license number.
setup a calculate field to pull their license number from the layer based on the license number in the hosted feature. Then in your license number question in the constraints field build your constraint to make sure they match. I haven't tried pulling the same number I am matching however. Are there any other fields you can match in the hosted layer (customer id) or something incase retrieving the license number based on match that licensing number doesn't work?
Edit: Just checked and pulling the license number should working on matching the license number in the same field.
here is some code to get you started:
Lic_Number_Question constraint: .=${Hidden_Calculate_question}
WhCl calculate: concat("Lic_Num = ",${Lic_Number_Question})
Hidden_Calculate_question: calculate: pulldata("@layer", "getValue", "attributes.Lic_Num", "<url>", ${WhCl})
Thank you so much.
My pull data request is not working. I am worndering if this should work in survey123 connect before publishing.
This is the WhereContr calculation:
concat("CONTRACTNO='",${ApplicantContractorsLic},"'")
The where concatenation returns this CONTRACTNO='123456'
CONTRACTNO is a string field so I put it in quotes
I put this in the calculation field of another text field to see if it would return the CONTRACTNO:
pulldata("@layer","getValue", "attributes.CONTRACTNO","https://services.arcgis.com/xyzxyzxy/arcgis/rest/services/EXAMPLELicenses/FeatureServer/0", ${WhereContr})
I get values when directly putting this in the browser similar to this:
https://services.arcgis.com/xyzxyzxy/arcgis/rest/services/EXAMPLELicenses/FeatureServer/0/query?wher...
Try it with just this: concat("CONTRACTNO=",${ApplicantContractorsLic})
Unfortunately this didnt work either.
hmmm, So I recreated this with sample data and the workflow does work. And it appears from your test that your feature layer is queryable, so I am guessing that it is just a syntax error.
From here I would work backward, and start with hard coding your where clause ensuring you get something that works and once you have it working with a static url, move that syntax for the where clause to the helper question with the dynamic field as above.
pulldata("@layer","getValue", "attributes.CONTRACTNO","https://services.arcgis.com/xyzxyzxy/arcgis/rest/services/EXAMPLELicenses/FeatureServer/0", "CONTRACTNO=xyzxyzx")
or 'CONTRACTNO="xyzxyzx"' trying various syntax until you get it to return the correct license number.
Got it to work using the above format. I used single quotes around the text in the where clause
concat("CONTRACTNO='",${ApplicantContractorsLic}, "'")
Thank you for the help!
Glad it is working, interesting that it didn't work previously, it appears to be the same as in your previous post. Sometimes getting the syntax correct is the hardest part.
Yeah, likely was the syntax somewhere else, I retyped everything out. Initially, it might have been some of the quotes in other spots. I lazily used word to type this out originally. The Word document quotes sometimes cause issues.
Never done something exactly like this, but I reckon that if you have the validation dataset available as a feature service (don't know if this is the same as a feature class, I'm still kinda naive...) within your AGOL portal, what you are seeking to do is 100% possible.
I think you could do this with pulldata("@json") - there may be other ways as well but here's how I would do this:
It might be easier to do this using a small .JS script to handle the query to the feature layer ( pulldata("@javascript") in that case) and return a JSON object that you can then use pulldata("@json") on for the validation.
You have a few ways to get there - feel free to DM me if you need a bit of extra help with this and I'll see if I can assist!