<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Preserve Editing Options when Overwriting Web Service with Python Script in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/preserve-editing-options-when-overwriting-web/m-p/1134627#M63527</link>
    <description>&lt;P&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;I have been working on implementing a Python script to automate overwriting web feature services hosted in ArcGIS Online each week.&lt;/P&gt;&lt;P&gt;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.&lt;BR /&gt;&lt;BR /&gt;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.&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;For example:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Enable Editing:&lt;/STRONG&gt; True&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;What kind of editing is allowed?&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&lt;STRONG&gt;Add:&lt;/STRONG&gt; False&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&lt;STRONG&gt;Delete:&lt;/STRONG&gt; False&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&lt;STRONG&gt;Update:&lt;/STRONG&gt; True&lt;/P&gt;&lt;P class="lia-indent-padding-left-60px"&gt;&lt;STRONG&gt;Attributes Only:&lt;/STRONG&gt; True&lt;/P&gt;&lt;P class="lia-indent-padding-left-60px"&gt;&lt;STRONG&gt;Attributes and Geometry:&lt;/STRONG&gt; False&lt;/P&gt;&lt;P class="lia-indent-padding-left-60px"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The 3rd feature service that I overwrite can allow all editing.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;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!&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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 = "http://www.arcgis.com" # 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, "WebUpdate.sd")

print("Creating SD file")
arcpy.env.overwriteOutput = True
prj = arcpy.mp.ArcGISProject(prjPath)
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"

sharing_draft.exportToSDDraft(sddraft)
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 = gis.content.search(query=sd_fs_name, item_type="Service Definition")
i=0
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]
item.update(data=sd)

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, fs.id))
&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 18 Jan 2022 16:43:14 GMT</pubDate>
    <dc:creator>ckmcit4141</dc:creator>
    <dc:date>2022-01-18T16:43:14Z</dc:date>
    <item>
      <title>Preserve Editing Options when Overwriting Web Service with Python Script</title>
      <link>https://community.esri.com/t5/python-questions/preserve-editing-options-when-overwriting-web/m-p/1134627#M63527</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;I have been working on implementing a Python script to automate overwriting web feature services hosted in ArcGIS Online each week.&lt;/P&gt;&lt;P&gt;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.&lt;BR /&gt;&lt;BR /&gt;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.&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;For example:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Enable Editing:&lt;/STRONG&gt; True&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;What kind of editing is allowed?&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&lt;STRONG&gt;Add:&lt;/STRONG&gt; False&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&lt;STRONG&gt;Delete:&lt;/STRONG&gt; False&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&lt;STRONG&gt;Update:&lt;/STRONG&gt; True&lt;/P&gt;&lt;P class="lia-indent-padding-left-60px"&gt;&lt;STRONG&gt;Attributes Only:&lt;/STRONG&gt; True&lt;/P&gt;&lt;P class="lia-indent-padding-left-60px"&gt;&lt;STRONG&gt;Attributes and Geometry:&lt;/STRONG&gt; False&lt;/P&gt;&lt;P class="lia-indent-padding-left-60px"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The 3rd feature service that I overwrite can allow all editing.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;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!&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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 = "http://www.arcgis.com" # 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, "WebUpdate.sd")

print("Creating SD file")
arcpy.env.overwriteOutput = True
prj = arcpy.mp.ArcGISProject(prjPath)
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"

sharing_draft.exportToSDDraft(sddraft)
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 = gis.content.search(query=sd_fs_name, item_type="Service Definition")
i=0
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]
item.update(data=sd)

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, fs.id))
&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jan 2022 16:43:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/preserve-editing-options-when-overwriting-web/m-p/1134627#M63527</guid>
      <dc:creator>ckmcit4141</dc:creator>
      <dc:date>2022-01-18T16:43:14Z</dc:date>
    </item>
  </channel>
</rss>

