Calculate field based on another feature service?

318
4
02-08-2021 10:11 AM
ShelbyZelonisRoberson
Occasional Contributor II

I'm trying to do something in Survey123 (Enterprise/Portal) that I don't know if possible.

Context: I have a form built that the public can fill out. On the backend (via Integromat), upon submittal a PDF report of the survey gets emailed to the submitting user and CC'd to an internal email address.

Question: The survey has a geopoint field. Can I take this data and use another feature service to essentially do a spatial join/point-in-polygon and calculate a new field in the survey with attribute information based on the external feature class? Basically - I want the form to autopopulate a District field based on the geopoint location. The District boundaries are in a separate feature class in my Portal. I intend to then filter the survey results in Integromat and only email each district's surveys to each district's POC. 

Thanks!! 

0 Kudos
4 Replies
ZacharySutherby
Esri Contributor

Hello @ShelbyZelonisRoberson

For your first question you can accomplish this by using a JavaScript function in your survey. Please refer to the JavaScript sample in Survey123 Connect there is a section that queries a Feature Service and returns attribute information based on the location of the Geopoint. 

Please use this link for more information on JavaScript functions in Survey123: https://community.esri.com/t5/arcgis-survey123-blog/extending-survey123-smart-forms-with-custom-js-f...

Please use this link for more information on limitations when using JavaScript functions in Survey123: https://doc.arcgis.com/en/survey123/desktop/create-surveys/pulldatajavascript.htm#ESRI_SECTION1_2A1B...

 

For your second question I don't think a Webhook would be best because they are more geared towards individual responses. What you can do is use the Survey123 module in the ArcGIS API for Python and specify the `where` parameter to return only records that match a certain District. Ismael wrote a good blog on using Python to configure an email notification system. The email piece of that script can be used to automatically send the email to the Districts email address. Or if you did want to use Webhooks you can use this workflow to use the Python API script in a Webhook. 

We are in the process of creating documentation to help understand the Survey123 module in the Python API, but I have attached a sample notebook that highlights how to work with Reports using Python.

 

Thank you,

Zach

ShelbyZelonisRoberson
Occasional Contributor II

Hi Zach - 

Thanks! So, I got the first part working in Survey123 Connect. I'm having the survey pull data from our districts layer and populate a District ID field based on the geopoint. It works fine when I test it in Connect, but when I publish it and access it via a web form, the District ID does not populate in my survey. Any thoughts? I'm using the new beta geocode appearance for the geopoint, if that matters. 

As for the email... I think I found a way to do what I need in Integromat, but I'll need this District ID field to work before I can test it completely. 

Shelby 

0 Kudos
ShelbyZelonisRoberson
Occasional Contributor II

@ZacharySutherby  update to my last post:  I think it maybe does have something to do with the beta geocode appearance I'm using? For the geocode, I have the user enter an address (NOT on a map, but just by typing, according to instructions provided to me by @IsmaelChivite on this post: https://community.esri.com/t5/arcgis-survey123-questions/set-default-geosearch-parameters/m-p/102296... ). In the web form, a matching address populates another field that corresponds to the selected address. This functionality is known to not work in Connect or the App, but it works perfectly in the web form.

It seems I'm having the opposite problem with this District ID field. The District populates correctly in Connect and the App, but not in the web form (where I really need it!). Any ideas of how to fix it so it works in the web form? 

Thanks again!

 

EDIT: my survey is public - I guess that’s why it isn’t working? Is there any workaround for this? The functionality is exactly what I’m looking for!

0 Kudos
DougBrowning
MVP Frequent Contributor

No you cannot use javascript in public surveys or across orgs.  Security thing so that is not going to change.  If offline out of luck also.

0 Kudos