Preserve Editing Options when Overwriting Web Service with Python Script

01-18-2022 08:43 AM
New Contributor


I have been working on implementing a Python script to automate overwriting web feature services hosted in ArcGIS Online each week.

I have setup a script that works well and I run it in ModelBuilder in ArcGIS Pro to update about 6 different services each week.

3 of the services that are overwritten each week need to have editing enabled for other users in the organization to be able to edit the services each week. Currently, when I overwrite these services, the editing parameters I have selected are reset (all editing disabled) when I overwrite the layers with my script. This requires me to have to log in to ArcGIS Online and reconfigure the editing parameters on each layer every week, which I would like to automate in my script.

To make matters more complicated, ArcGIS Online allows me to select which types of edits are allowed and I would like to be able to keep my settings. On 2 of the layers, I need to have only attribute updates allowed.

For example:

Enable Editing: True

What kind of editing is allowed?

Add: False

Delete: False

Update: True

Attributes Only: True

Attributes and Geometry: False


The 3rd feature service that I overwrite can allow all editing. 

Is it possible to add these parameters to my overwrite script to automate the steps of configuring these settings? I will include the Python script I am using below. Thanks in advance!


import arcpy
import os, sys
from arcgis.gis import GIS

prjPath = r"C:\myfilepath\myprojectfile.aprx"

sd_fs_name = arcpy.GetParameterAsText(0) #Enter Feature Service Name in Script tool Parameter
portal = "" # Can also reference a local portal
user = "myusername"
password = "mypassword"

shrOrg = True
shrEveryone = False
shrGroups = ""

relPath = r"C:\myfilepath"
sddraft = os.path.join(relPath, "WebUpdate.sddraft")
sd = os.path.join(relPath, "")

print("Creating SD file")
arcpy.env.overwriteOutput = True
prj =
mp = prj.listMaps()[0]

sharing_draft = mp.getWebLayerSharingDraft("HOSTING_SERVER", "FEATURE", sd_fs_name)
sharing_draft.summary = "My Summary"
sharing_draft.tags = "My Tags"
sharing_draft.description = "My Description"
sharing_draft.credits = "My Credits"
sharing_draft.useLimitations = "My Use Limitations"

arcpy.StageService_server(sddraft, sd)

print("Connecting to {}".format(portal))
gis = GIS(portal, user, password)

# Find the SD, update it, publish /w overwrite and set sharing and metadata
print("Search for original SD on portal…")
print(f"Query: {sd_fs_name}")
sdItem =, item_type="Service Definition")
while sdItem[i].title != sd_fs_name:
i += 1
print('Item Found')
print(f'item[i].title = {sdItem[i].title}, sd_fs_name = {sd_fs_name}')
item = sdItem[i]

print("Overwriting existing feature service…")
fs = item.publish(overwrite=True)

if shrOrg or shrEveryone or shrGroups:
print("Setting sharing options…")
fs.share(org=shrOrg, everyone=shrEveryone, groups=shrGroups)

print("Finished updating: {} – ID: {}".format(fs.title,


0 Kudos
0 Replies