Is it possible to auto populate answers based on location?

389
3
Jump to solution
10-06-2021 05:45 AM
3CDCOrganizationalAccount
New Contributor III

I am not sure if this is even possible but is it possible to automatically populate answers in a survey based on a individual's location/geopoint? I have a survey in which employees fill out a job report and some of the questions include which district and what zone they are in, as well as create a geopoint on a map.

In order to save them time, I was wondering if it is possible to reference their geopoints to a map of the districts/zones and get information on where they are? I know it might be unlikely but I would love to hear any ideas.

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
DeonLengton
Esri Contributor

Hi

This is totally possible if you have a logged in user - you can perform a live query via JavaScript to a feature layer and extract information based on, for instance, the closest or an intersecting facility by using the ArcGIS REST API:

var url = featureLayer + "/query?where=1=1&geometry=" + coords + "&geometryType=esriGeometryPoint&inSR=4326&spatialRel=esriSpatialRelIntersects&outFields=*&returnGeometry=false&returnCount=1&f=json"

You can then manipulate the return of the call to retrieve the attributes and use them in your survey:

return JSON.stringify(responseJSON.features[0]);

pulldata("@javascript","myFunctions.js","queryPolygon",string(${location}),true)
pulldata("@json",${my_json},"attributes.Region")

 

Please see this blog for more info:

https://community.esri.com/t5/arcgis-survey123-blog/extending-survey123-smart-forms-with-custom-js/b...

View solution in original post

3 Replies
DeonLengton
Esri Contributor

Hi

This is totally possible if you have a logged in user - you can perform a live query via JavaScript to a feature layer and extract information based on, for instance, the closest or an intersecting facility by using the ArcGIS REST API:

var url = featureLayer + "/query?where=1=1&geometry=" + coords + "&geometryType=esriGeometryPoint&inSR=4326&spatialRel=esriSpatialRelIntersects&outFields=*&returnGeometry=false&returnCount=1&f=json"

You can then manipulate the return of the call to retrieve the attributes and use them in your survey:

return JSON.stringify(responseJSON.features[0]);

pulldata("@javascript","myFunctions.js","queryPolygon",string(${location}),true)
pulldata("@json",${my_json},"attributes.Region")

 

Please see this blog for more info:

https://community.esri.com/t5/arcgis-survey123-blog/extending-survey123-smart-forms-with-custom-js/b...

3CDCOrganizationalAccount
New Contributor III

Wow, thanks! I will try to play around with this and see if I can get this to work. 

0 Kudos
ahargreaves_FW
Occasional Contributor II

@DeonLengton , is it possible to go one step further and populate a survey question based on features in the current map extent? eg: if i zoom in tight enough so there's only a single hydrant displayed the survey auto-populates with that Hydrants ID?

0 Kudos