Select to view content in your preferred language

Turning off editing field by field?

218
3
Jump to solution
3 weeks ago
Labels (1)
MatthewStull1
Frequent Contributor

I have a hosted feature layer with 24 fields in it.  I want to turn off editing on all of the fields except one.  Do I really need to go one at a time and turn off the editing field by field for the other 23?   I'm doing this in the "Data" tab "Fields" view of my layer's information page.  Is there a quicker way to do this?  If not, that is not great.  Is there a way for me to easily turn off field by field editing in the Map Viewer (I don't think there is)?  Anyway, if I do have to go field by field and turn off editing, that's not great and I will submit that as an enhancement idea.

0 Kudos
1 Solution

Accepted Solutions
EmilyGeo
Esri Contributor

Hi @MatthewStull1

You can create a form in Map Viewer. Select which fields to add to the form by dragging and dropping them on to the canvas. In your case, you can simply add 1 field to the form. 

EmilyGeo_1-1737070328565.png

View solution in original post

3 Replies
EmilyGeo
Esri Contributor

Hi @MatthewStull1

You can create a form in Map Viewer. Select which fields to add to the form by dragging and dropping them on to the canvas. In your case, you can simply add 1 field to the form. 

EmilyGeo_1-1737070328565.png

MatthewStull1
Frequent Contributor

Thank you, that worked great!

0 Kudos
MobiusSnake
MVP Regular Contributor

I usually script this type of thing up if it's something I'm doing more than once - particularly when I have a hosted feature layer with a large number of views hanging off of it, and I need to modify all of the views.  Below is an example of code where I disable editing on all fields except two named lifecycle_status and review_notes.  I modify the two constants at the top for the view's Item ID and the layer/table indices that should be editable.

There are a couple improvements that could be made to this; the field property updates could be bundled together into a single call to update_definition, that would make it quicker, and the field names that remain editable could be put into a list at the top of the code rather than being hardcoded in the middle.

VIEW_ITEM_ID = "your_item_id_here"
EDIT_DATASET_IDX_LIST = [0]

from arcgis.gis import GIS
from arcgis.features import FeatureLayerCollection

# Connect to the view.
gis = GIS("home")
content = gis.content
view_item = content.get(VIEW_ITEM_ID)
if view_item is None:
    raise Exception("View item not found.")
view_flc = FeatureLayerCollection.fromitem(view_item)

# Iterate through each of the layers and tables.
view_datasets = view_flc.layers + view_flc.tables
for view_dataset in view_datasets:
    # Determine whether we want any editable fields.
    view_dataset_idx = view_dataset.properties["id"]
    dataset_editable = view_dataset_idx in EDIT_DATASET_IDX_LIST
    
    # Iterate through the fields, updating those that are editable and not related to approval.
    view_dataset_manager = view_dataset.manager
    for field_def in view_dataset.properties["fields"]:
        if not field_def["editable"]:
            continue
        if dataset_editable and "lifecycle_status" in field_def["name"]:
            continue
        if dataset_editable and "review_notes" in field_def["name"]:
            continue
        
        # Put together a dictionary for the manager update call.
        def_update = {
            "fields": [
                {
                    "name": field_def["name"],
                    "editable": False
                }
            ]
        }
        view_dataset_manager.update_definition(def_update)

print("Finished.")

.