I'm using a Python script that updates an ArcGIS Online hosted feature layer.
The script runs OK but unselects "Enable Sync (required for offline use and collaboration)" and "Allow others to export to different formats".
I'd like the script to re-enable both settings during the update. Below is a copy of the current script. Any assistance would be appreciated.
import arcpy
import os, sys
from arcgis.gis import GIS
### Start setting variables
# Enter the path to the AGP Project that was used to publish the service to AGOL
prjPath = r"C:\GIS_Scripts\SmarterWX\SMWXAuto.aprx"
# Enter AGOL Service Definition Name
sd_fs_name = "DBYD"
portal = "http://www.arcgis.com" # Can also reference a local portal
# Enter credentials for the owner of the AGOL Service
user = "********"
password = "********"
# Set Sharing Options
shrOrg = True
shrEveryone = False
shrGroups = "DBYD"
### End settng variables
# Enter the path to the temporary output location
relPath = r'C:\GIS_Scripts\SmarterWX\SMWXAutoOut'
sddraft = os.path.join(relPath, "temporary service name.sddraft")
sd = os.path.join(relPath, "temporary service name.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", "DBYD")
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))
Thank you