Select to view content in your preferred language

How to reset a field in all records (features) in a layer using EB

243
3
06-04-2025 12:18 PM
JoseSanchez
Frequent Contributor

Good afternoon

How can I add in an EB application for editors/administrators the following functionality to a specific layer.  Reset a field to a default value, "No".

How will you implement this?  What type of widget do you recommend? 

 

In Python and ArcGIS Pro and Notebook I will do something like that:

feature_class = "your_feature_class"

with arcpy.da.UpdateCursor(feature_class, ["Flag"]) as cursor:
  for row in cursor:
      row[0] = "" # Set the "Flag" field to an empty string
      cursor.updateRow(row)

 

 

0 Kudos
3 Replies
Allen_Zhang
Frequent Contributor

In the coming release(2025 summer), the Edit widget includes a batch editing feature.

Or you can develop a custom widget with JSAPI's "FeatureForm" widget and the REST API's "applyEdits".

https://developers.arcgis.com/javascript/latest/sample-code/editing-applyedits/

https://developers.arcgis.com/experience-builder/guide/getting-started-widget/

0 Kudos
JoseSanchez
Frequent Contributor

Thank you @Allen_Zhang 

Also regular Web Maps have a feature that allows to run a Calculate Field  in a column.

 

I was thinking about adding an analysis widget and running a a Geoprocessing Tool to Run Calculate Field on a Hosted Feature Layer in ArcGIS Online (AGOL).

Something like that:

 

from arcgis.gis import GIS

# Connect to AGOL
gis = GIS("home")

# Get the feature service item
item = gis.content.get("YOUR_FEATURE_SERVICE_ITEM_ID")
layer = item.layers[0] # or use layer name

# Query features
features = layer.query(where="1=1").features

# Update field values
for feature in features:
# Example calculation: FieldC = FieldA + FieldB
feature.attributes["FieldC"] = feature.attributes["FieldA"] + feature.attributes["FieldB"]

# Apply edits
layer.edit_features(updates=features)

 

 

Allen_Zhang
Frequent Contributor

Also a good solution!

0 Kudos