Hi,
I am creating a survey to assist with environmental regulatory compliance for my client. I would like for survey users to be able to select their location and have the Hydrologic Unit Code (HUC) associated with that area autofill. For example, for the yellow point in the area shown below I want to have 020801060401 automatically fill in a separate field.
I know that I can reference the X,Y points from the Geopoint type using the pulldata() function (using pulldata("@geopoint", ${location}, "x"). Is it possible to then intersect that point with another feature service and put the HUC value into my survey?
Thanks in advance.
Solved! Go to Solution.
Hi Linnea
Using spatial inheritance to populate surveys based on information from another layer is not currently supported in Survey123 out of the box. However, we have added support for custom JavaScript functions (this functionality currently is in beta) and you could use this to achieve what you are wanting to do. Essentially you would need to write a script that would take the survey location and use it to do a spatial query against your HUC layer. Please take a look at the following resource for more information on this functionality: Welcome to our Feedback Community. Of course, some JavaScript skills would be required to implement this.
Thanks
John
Hi Linnea
Using spatial inheritance to populate surveys based on information from another layer is not currently supported in Survey123 out of the box. However, we have added support for custom JavaScript functions (this functionality currently is in beta) and you could use this to achieve what you are wanting to do. Essentially you would need to write a script that would take the survey location and use it to do a spatial query against your HUC layer. Please take a look at the following resource for more information on this functionality: Welcome to our Feedback Community. Of course, some JavaScript skills would be required to implement this.
Thanks
John
Thanks! Even with very limited javascript experience it was easy to edit the functions found in the example to get the functionality I need. It's not displaying quite correctly yet, but is reading the feature service and automatically fills the HUC fields with the correct info based on the X,Y point. This is great!
Hi Linnea,
Would you mind shedding some light on how you accomplished this?
I'm trying to do the exact same thing with HUCs and Ecoregions but can't seem to get my script to work.
Hi Chris,
I used the example script posted on the page that John Hasthorpe provided above (Welcome to our Feedback Community ). I modified the associated json file to call the polygon feature services I needed. This process is described in the above link. The example script only works for point features within polygons, so you will have to do more customizing for polygons in polygons. That may be especially complicated because the JavaScript features you can use in the extensions are so limited, as described in the above link. Please let me know if you get a script to work for polygons in polygons! That would be helpful to know.
Best,
Linnea
Thanks Linnea,
I got the example script to work using a few different hosted feature layers in the same form. Awesome functionality!
Is this still a issue that's only fixed in a Beta version? I've been trying to run the pulldata(@javascript) function but it's throwing errors still.
Thanks
Tyler
Hi Tyler - can you share your survey and JS file. This functionality is working in beta.
Cheers
John
Hey John,
thanks for the reply. I've been trying to run it in normal survey123 cause I didn't know if it had been pushed out of beta yet. I'll install the beta version and set it up. Question for you though, If i build a survey in the beta version, can the team in the field access it normally through the Survey123 app or do they need to download a different version?
Thanks
Tyler
Hi Tyler
Just to clarify - the functionality is in beta. But you can use it in the released version of the app (version 3.0).
It is likely that the error message is not related to the version you are using. Please share your files and I'll take a look.
Thanks
John