Select to view content in your preferred language

Conditional Field display with Arcade in Pop Ups

84740
118
07-18-2017 11:53 AM
KellyGerrow
Esri Alum
42 118 84.7K

The June 2017 Release of ArcGIS Online enabled the capability to write custom Arcade expressions for use in Pop Ups!! A common request was to be able to format pop ups to display attribute values and labels when values are present and not have them appear when the values are blank. Although there are plans to incorporate this functionality directly into the pop up in the future, it is currently possible to use Arcade and Custom Attribute Displays to accomplish this.

I'm going to use an existing example of my Heron Watch Data and display the description when one is present. I will hide the field value and field label when it isn't present. View the Heron location in Singapore to see a feature with no description, or add features using this GeoForm App with no description.  

Check out the steps below to accomplish this and then share your real examples!

Step 1: Create an Arcade Expression that tests for values using IsEmpty. This will be used to determine if the label for the attribute needs to be displayed or not. 

Sample code:

    IIF(isEmpty($feature.description), "", "Description")

If the feature is empty, a blank value will be returned. If there is a value, the label "Description" will be returned in the expression.

2. Configure a table using Custom Attribute Display in the pop ups that is configured to use the expression as the label.

        Custom Attribute

    - Enable the option to view Source HTML:

    

- Create a table using the HTML  sample below. The text in curly brackets refer to attribute values in the feature layer. The plain text between the first table elements specifies the label for each attribute.

<table cellpadding="0px" cellspacing="3px">
     <tbody>
           <tr valign="top">
               <td><b>Observed Time (UTC)</b></td>
               <td><span>{viewed}</span> 
               </td>
            </tr>
            <tr valign="top">
               <td><b> Observed Time (Local) </b></td>
               <td>{textviewed}</td>
            </tr>
            <tr valign="top">
              <td><b>Species</b></td>
              <td>{type_of_heron}</td>
            </tr>
           <tr valign="top">
               <td><b>{expression/expr0}</b></td>
               <td>{description}</td>
           </tr>
      </tbody>
</table>‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

- Note that {expression/expr0} is the value of the Arcade expression created in Step 1 that is used for the attribute label and the description value is used for the value. If no value is present in the description there will also be no value for the label.

- Unselect the HTML Source option and your formatted pop up configuration should look similar to this screen shot:

3. Save your Web Map and make an app to show off your Pop Ups

Description Values Present:

Description Values not Present

If you don't want to use a table to display your attributes, consider integrating this workflow with free text and calculated Arcade Expressions as outlined in this blog by Bernie Szukalski:

https://blogs.esri.com/esri/arcgis/2015/12/28/custom-attribute-display-pop-ups/ 

118 Comments
About the Author
I love interactive maps and apps on the internet! The maps and apps that customers create and share on the web, make my job awesome. I'm a Product Manager with the ArcGIS Online team in Redlands, California. I am a proud graduate from Carleton University and the COGS in Canada, with research focus' in Health Geography. Originally from Bedford, NS, Canada but have spent a lot of time in Haliburton and Ottawa, Ontario. I have a passion for the outdoors and dogs.