Survey123 is an incredible app from Esri that makes it really easy to configure data capture surveys. I've previously looked at how to implement a custom Other field and how to make survey results easier to analyse, or symbolise, when a survey includes the Other functionality. These methods use configuration options in the Survey123 Connect for ArcGIS desktop application. Supposing you’ve created your survey using the web designer, or perhaps you are happy with your existing surveys and don’t want to change them? In this blog I explore how to work with results that include the Other functionality, after the survey has been published.
If you're not aware, the Other functionality allows users to enter an Other value as an answer to a multiple choice question if the answer they need is not in the list. This has been implemented for the question What is the property type?:
This functionality is awesome, but the Other value that a user inputs is assigned to a new field in the attribute table. This means the answers for one question are spread over two fields:
Arcade can help us with this! Arcade is a cross-platform expression language for ArcGIS and, since June 2017, we can use Arcade in web map pop ups. So we can manipulate the contents of pop ups and, in this instance, display the correct entry for the question What is the property type?
This blog assumes you have published a survey using the Survey123 Web Designer or Connect, with at least one Single Choice (web designer) or select_one (Connect) question with Other enabled. You can do this using the standard method or the alternative one I shared before.
Using Arcade with Other
1) Add the Survey123 data to a web map
2) Navigate to the Configure Pop Up pane > under Attribute Expressions click Add
3) Specify a name for the Attribute Expression
4) Now we need to form the expression. In simple terms, if the answer to a question is ‘other’, then ignore it and give us the alternate answer supplied instead. In Arcade, this translates into:
IIf($feature.fieldname == "other", $feature.fieldname_other, DomainName($feature,"fieldname"))
For the question in this example; ‘What is the property type’ is the field alias and ‘PropertyType’ is the field name so the expression looks like:
IIf($feature.PropertyType == "other", $feature.PropertyType_other, DomainName($feature,"PropertyType"))
Click Test to ensure the expression works correctly. When you’re happy, click OK to close the window.
Note: Arcade expressions are case sensitive, 'other' might be 'Other' or another phrase depending on your survey question.
5) In the Configure Pop Up pane, choose A list of field attributes for the Display option > click Configure Attributes. The Attribute Expression created in the previous step will appear at the bottom of the list. Enable this attribute, reorder and turn off the two fields it is replacing:
Click OK to close the Configure Pop Up pane
6. Click on a feature to see the results!
- You can find the field names from the Globals section in the Attribute Expression window
- If you are referencing a field’s domain in the expression, you need to use the domain code and not the name. You can find this in the Attribute Expression window by clicking on the little pencil beside the field name under Globals.
- If you created your survey using the Survey123 Web Designer, please note that the field names usually are field_0, field_0_other, field_1 etc.
- Under Globals, fields that have domains include extra information:
If you use the Code then domain codes will be returned in the pop up, whereas if you use DomainName($feature,”PropertyType”) the domain names will be returned instead and will look better.
- Attribute Expressions can also be used in Custom Attribute Displays too, have a go!
Using Arcade in this way means no changes are made to the information at a database level but how the information is relayed to end users is improved!