Select to view content in your preferred language

Use the filtered value as a default field value

1656
2
12-29-2023 01:26 PM
Labels (2)
AlixVezina
Esri Regular Contributor
5 2 1,656

Topic – Migrating from Web AppBuilder to Experience Builder

The Smart Editor widget in Web AppBuilder provides a variety of configuration options to save time for editors by enforcing data integrity with field conditions and automating the calculation of field values.

Much of this functionality is now available through Smart Forms. To learn more, check out this blog: From the Smart Editor to Smart Forms

The functionality we describe in this blog belongs to very specific workflows and we thought it may deserve a dedicated post.

 

In Web AppBuilder

In Web AppBuilder, you can set up an interaction between the Group Filter widget and the Smart Editor widget to use the filtered value as a default value for attribute fields when you create new features.

As illustrated in the example app below, when a user filters features from the Event map to view a specific event, the event name value will be automatically populated into the Event identifier field for any new features they create for that event.

GF-SE_filterValue.png

This option can be enabled in the Smart Editor widget General Settings, along with setting up Preset Attribute Actions and proper filters in the Group Filter widget.

GF-SE_filterValue2.png

In Experience Builder

To recreate this functionality in Experience Builder, you’ll need to configure Forms in Map Viewer for your editable layers. Add a calculated expression to the form using Arcade to calculate and populate data automatically.

Follow these steps with this sample map to view an example:

1. In Map Viewer, apply a new Filter Expression on the Filtered Layer for one of the values (e.g., value 5 below).

GF-SE_filterValue3.png

2. Then, use the Edit tool to add a new feature for the Editable Layer.

GF-SE_filterValue4.gif

 

Notice how the value from the remaining feature (value 5, in the example above) is written into the field automatically.

How was this achieved? Let’s take a look at the Form:

3. Open the Forms configuration for the Editable Layer. 

GF-SE_filterValue5.png

4. For the Value from filter field you'll see a Calculated expression is set.

GF-SE_filterValue6.png

5. Click the gear and Edit Arcade to view and modify the expression. 

GF-SE_filterValue7.png

6. For an expression using your own layers in your own web map, you'll need to replace the elements underlined in red and blue below.

GF-SE_filterValue8.png

  • Red: the layer and field the filtered value is coming from.
  • Blue: the target field for the filtered value in the target layer (this is the one for which you are configuring the Form).

Here's the code snippet:

 

function getValue() {
  // Define which layer and field to grab the value from
  var queryLayer = FeatureSetByName($map, "Filtered Layer", ["Value_to_filter"], false);
  // Return the value from the first feature returned when querying that layer
  var firstFeature = First(queryLayer);
  if (IsEmpty(firstFeature)) 
    return null; // Layer is empty.
  return firstFeature["Value_to_filter"];
}
// Only perform this calculation when a new feature is created
if ($editContext.editType == "INSERT" && $feature.Value_from_filter == null) { 
  return getValue()
} else { 
  // When the feature is updated, return the existing value in this field
  // and do not calculate a new value
  return $feature.Value_from_filter
}

 

Note: this will only work as expected if a filter is applied. If no filter is applied, an unexpected value may be populated.

 

Once you've set the Calculated expression in the Map Viewer using the Forms, this logic will also work when using this web map in Experience Builder with the Filter and Edit widgets.

Check out this application example:

GF-SE_filterValue10.gif

 

We must all thank @ChrisDelaney for coming up with this approach!

2 Comments
About the Author
Alix Vézina is a senior product engineer on Esri's ArcGIS Solutions Web Development team, where she has successfully delivered industry web mapping tools since 2019. Her previous work includes assisting in the digital GIS transformation of a property and land-management organization in New Zealand and coauthoring ArcGIS learning resources for the Public Safety sector. In her free time, Alix enjoys hiking with her puppy in the Colorado foothills.