We have several survey forms with individual fields that are populated with the results returned by custom javascript. We now have a need to populate a select_one dropdown with choices returned from a javascript function. Is this possible in the latest version of Survey123?
That is a slick way to filter a list of choices that already exist. In my case, I would have to put 100's of thousands of choices into the spreadsheet to cover all the possibilities that are stored in the feature service. What I am looking to do is dynamically define the choices without having to store any predefined values in the excel choice tab.
Oh! I see, you'd like the list of choices filtered, not just pre-selected. I think the only way to do this is to utilize the choice_filter column. See: https://community.esri.com/t5/arcgis-survey123-blog/survey123-tricks-of-the-trade-choice-filters/ba-p/894046
I haven't combined a JS function and a choice filter before, but this is still doable using a hidden question and a choice filter.
Here's my test. You can see that my options are limited to those items in my string list.
EDIT: I should say, set that hidden question to a null type so it's not part of the output schema.
Thanks Josh. Sorry I should have been more specific. What I want to do is define the choices for the dropdown dynamically. For example, in javascript I send the form's geopoint to the ArcGIS REST API, buffer the point 300ft and return all polygons from a feature service that intersect the buffer. Then I want to define the choices in a dropdown with the attribute values from the returned list of polygons. All of that already works except for the last part where the dropdown choices are defined. So far I haven't found any syntax to use in the excel form that will override the choices that are static in the choices tab.
It should be, but depends on what your function is returning. Are you able to share your code / xlsform?
In general, if your JS function is returning a simple string or numeric value, you can use pulldata("@javascript", "your-functions.js", "some-function", "parameter1", ... "parameterN") right in the calculation section of the XLSForm. As long as what your function returns corresponds with a defined choice for the question, this should work just fine.
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.