Select to view content in your preferred language

How to override values for fields with calculated expressions

543
20
03-25-2024 01:10 PM
ShareUser
Esri Community Manager
0 20 543

You can save time collecting data and automatically calculate attribute values using the Editor widget with "smart" Forms. The Editor widget is available in Map Viewer and app builders such as Experience Builder and Instant AppsThe Forms builder is available in Map Viewer and Field Maps Designer; all you need is an editable feature layer.

If this is your first time, read this blog to get started building Forms.

 

Challenge

The values for fields with calculated expressions cannot be edited or recalculated on demand, while editable fields do not support calculated expressions.

Common use cases for the need to override a calculated value:

  • When the calculated expression fetches values from intersecting features: if multiple features are intersected, an unexpected value can be returned which needs correcting.
  • Calculated values based on other field values: if the other values are incorrect, manual adjustments may be required.
  • When the calculated expression doesn't return any value (blank/null): users may need to enter a value manually.

 

Workaround

Leverage field Logic in Forms to set dynamic behavior for editability based on a condition.

Open this sample Feature Layer in Map Viewer to view an example.

In the provided example, an editable feature layer has a Current Date field for which the value is automatically calculated based on the current date and time. Another field is used to define conditional editability for the Current Date field. If the Current Date field is editable, the date value can be changed. If the Current Date field is not editable, the date value is calculated and cannot be changed.

Override_Calc_exp.gif

 

Follow the steps below to incorporate this field Logic into your editable layers.

 

Step 1 - Update your data schema

Note: This workaround may impact your data model as you may need to add a new field to your layer.

  1. For a new editable layer or an existing layer, add a new field of type String
    • Give the field a name (e.g. Change Date in the sample layer)
    • The field must be Editable
    • The default value for the field should be "No"
  2. Add a List of Values (domain) for the field.
    • Values should be "Yes" and "No"

AlixVezina_0-1711388939928.png

 

Step 2 - Add the calculated field to the Form

  1. In Map Viewer or the Field Maps Designer app, create a Form for the layer.
  2. To the Form, add the field for which a value needs to be calculated (e.g. Current Date in the sample layer).
  3. Under Logic, define the Calculated expression using Arcade.
    In the example below, the expression Now() will automatically populate the current date and time into the Current Date field.

AlixVezina_1-1711389150835.png

 

Step 3 - Add the conditional field to the Form

  1. To the Form, add the field that end-users will use to make the Current Date field editable (Change Date in the sample layer).
  2. Under Formatting, update the Display name for the field (e.g. Toggle to override the date value above)
  3. Change the Input type to Switch.

AlixVezina_1-1711394672338.png

 

Step 4 - Add Logic for the calculated field

  1. For the calculated field (Current Date), under Logic, check the box for Editable and configure a new expression. (e.g. the Current Date field becomes editable if the Change Date field value is "Yes")
  2. Optionally, add an expression to make the field required if it's blank.

AlixVezina_2-1711396222917.png

AlixVezina_1-1711396077567.png

 

__________________

Special thanks to @ChrisFox@DougMorgenthaler and the Field Maps team for sharing this approach.

 

 

You might also like

 

20 Comments
Labels