<?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 Re: Update an ArcGIS Online hosted feature layer using a Python Script in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/update-an-arcgis-online-hosted-feature-layer-using/m-p/1299114#M67964</link>
    <description>&lt;P&gt;It would help if you pasted your code with formatting:&amp;nbsp; click the '...', then '&amp;lt;/&amp;gt;', paste in the code in the window and select python.&lt;/P&gt;&lt;P&gt;There is a section in the docs for enabling sync- &lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/sharing/featuresharingdraft-class.htm#GUID-66C9D925-CE68-4A50-BD5C-2910AA65C636" target="_blank" rel="noopener"&gt;featuresharingdraft-class&lt;/A&gt; and the export, it is a property in the service definition draft you can set.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;sharing_draft.allowExporting = True&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This statement is convoluted:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;if shrOrg or shrEveryone or shrGroups:
    print("Setting sharing options…")
    fs.share(org=shrOrg, everyone=shrEveryone, groups=shrGroups)&lt;/LI-CODE&gt;&lt;P&gt;and is really saying as set:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;if True or False or 'DBYD':
    print("Setting sharing options…")
    fs.share(org=shrOrg, everyone=shrEveryone, groups=shrGroups)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;The conditional really isn't doing anything.&lt;/P&gt;&lt;P&gt;Check the example for sharing in the same featuresharingdraft docs- it uses an xml editor to edit the sddraft. Why it cant be an exposed property like the others when creating the sddraft is a mystery.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Change following to "true" to share
SharetoOrganization = "false"
SharetoEveryone = "true"
SharetoGroup = "false"
# If SharetoGroup is set to "true", uncomment line below and provide group IDs
GroupID = ""    # GroupID = "f07fab920d71339cb7b1291e3059b7a8, e0fb8fff410b1d7bae1992700567f54a"

# Each key has a corresponding value. In all the cases, value of key_list[i] is value_list[i].
for i in range(key_list.length):
    if key_list[i].firstChild.nodeValue == "PackageUnderMyOrg":
        value_list[i].firstChild.nodeValue = SharetoOrganization
    if key_list[i].firstChild.nodeValue == "PackageIsPublic":
        value_list[i].firstChild.nodeValue = SharetoEveryone
    if key_list[i].firstChild.nodeValue == "PackageShareGroups":
        value_list[i].firstChild.nodeValue = SharetoGroup
    if SharetoGroup == "true" and key_list[i].firstChild.nodeValue == "PackageGroupIDs":
        value_list[i].firstChild.nodeValue = GroupID

# Write to the .sddraft file
f = open(sddraft_output_filename, 'w')
docs.writexml(f)
f.close()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 14 Jun 2023 13:06:19 GMT</pubDate>
    <dc:creator>Anonymous User</dc:creator>
    <dc:date>2023-06-14T13:06:19Z</dc:date>
    <item>
      <title>Update an ArcGIS Online hosted feature layer using a Python Script</title>
      <link>https://community.esri.com/t5/python-questions/update-an-arcgis-online-hosted-feature-layer-using/m-p/1299015#M67962</link>
      <description>&lt;P&gt;I'm using a Python script that updates an ArcGIS Online hosted feature layer.&lt;/P&gt;&lt;P&gt;The script runs OK but unselects "&lt;SPAN&gt;&lt;STRONG&gt;&lt;EM&gt;Enable Sync (required for offline use and collaboration)&lt;/EM&gt;&lt;/STRONG&gt;" and "&lt;STRONG&gt;&lt;EM&gt;Allow others to export to different formats&lt;/EM&gt;&lt;/STRONG&gt;".&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;import arcpy&lt;BR /&gt;import os, sys&lt;BR /&gt;from arcgis.gis import GIS&lt;/P&gt;&lt;P&gt;### Start setting variables&lt;/P&gt;&lt;P&gt;# Enter the path to the AGP Project that was used to publish the service to AGOL&lt;BR /&gt;prjPath = r"C:\GIS_Scripts\SmarterWX\SMWXAuto.aprx"&lt;/P&gt;&lt;P&gt;# Enter AGOL Service Definition Name&lt;BR /&gt;sd_fs_name = "DBYD"&lt;BR /&gt;portal = "&lt;A href="http://www.arcgis.com" target="_blank"&gt;http://www.arcgis.com&lt;/A&gt;" # Can also reference a local portal&lt;BR /&gt;# Enter credentials for the owner of the AGOL Service&lt;BR /&gt;user = "********"&lt;BR /&gt;password = "********"&lt;BR /&gt;# Set Sharing Options&lt;BR /&gt;shrOrg = True&lt;BR /&gt;shrEveryone = False&lt;BR /&gt;shrGroups = "DBYD"&lt;/P&gt;&lt;P&gt;### End settng variables&lt;/P&gt;&lt;P&gt;# Enter the path to the temporary output location&lt;BR /&gt;relPath = r'C:\GIS_Scripts\SmarterWX\SMWXAutoOut'&lt;BR /&gt;sddraft = os.path.join(relPath, "temporary service name.sddraft")&lt;BR /&gt;sd = os.path.join(relPath, "temporary service name.sd")&lt;/P&gt;&lt;P&gt;print("Creating SD file")&lt;BR /&gt;arcpy.env.overwriteOutput = True&lt;BR /&gt;prj = arcpy.mp.ArcGISProject(prjPath)&lt;BR /&gt;mp = prj.listMaps()[0]&lt;/P&gt;&lt;P&gt;sharing_draft = mp.getWebLayerSharingDraft("HOSTING_SERVER", "FEATURE", "DBYD")&lt;BR /&gt;sharing_draft.summary = "My Summary"&lt;BR /&gt;sharing_draft.tags = "My Tags"&lt;BR /&gt;sharing_draft.description = "My Description"&lt;BR /&gt;sharing_draft.credits = "My Credits"&lt;BR /&gt;sharing_draft.useLimitations = "My Use Limitations"&lt;/P&gt;&lt;P&gt;sharing_draft.exportToSDDraft(sddraft)&lt;BR /&gt;arcpy.StageService_server(sddraft, sd)&lt;/P&gt;&lt;P&gt;print("Connecting to {}".format(portal))&lt;BR /&gt;gis = GIS(portal, user, password)&lt;/P&gt;&lt;P&gt;# Find the SD, update it, publish /w overwrite and set sharing and metadata&lt;BR /&gt;print("Search for original SD on portal…")&lt;BR /&gt;print(f"Query: {sd_fs_name}")&lt;BR /&gt;sdItem = gis.content.search(query=sd_fs_name, item_type="Service Definition")&lt;BR /&gt;i=0&lt;BR /&gt;while sdItem[i].title != sd_fs_name:&lt;BR /&gt;i += 1&lt;BR /&gt;print('Item Found')&lt;BR /&gt;print(f'item[i].title = {sdItem[i].title}, sd_fs_name = {sd_fs_name}')&lt;BR /&gt;item = sdItem[i]&lt;BR /&gt;item.update(data=sd)&lt;/P&gt;&lt;P&gt;print("Overwriting existing feature service…")&lt;BR /&gt;fs = item.publish(overwrite=True)&lt;/P&gt;&lt;P&gt;if shrOrg or shrEveryone or shrGroups:&lt;BR /&gt;print("Setting sharing options…")&lt;BR /&gt;fs.share(org=shrOrg, everyone=shrEveryone, groups=shrGroups)&lt;/P&gt;&lt;P&gt;print("Finished updating: {} – ID: {}".format(fs.title, fs.id))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2023 04:33:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-an-arcgis-online-hosted-feature-layer-using/m-p/1299015#M67962</guid>
      <dc:creator>crtownsend</dc:creator>
      <dc:date>2023-06-14T04:33:53Z</dc:date>
    </item>
    <item>
      <title>Re: Update an ArcGIS Online hosted feature layer using a Python Script</title>
      <link>https://community.esri.com/t5/python-questions/update-an-arcgis-online-hosted-feature-layer-using/m-p/1299114#M67964</link>
      <description>&lt;P&gt;It would help if you pasted your code with formatting:&amp;nbsp; click the '...', then '&amp;lt;/&amp;gt;', paste in the code in the window and select python.&lt;/P&gt;&lt;P&gt;There is a section in the docs for enabling sync- &lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/sharing/featuresharingdraft-class.htm#GUID-66C9D925-CE68-4A50-BD5C-2910AA65C636" target="_blank" rel="noopener"&gt;featuresharingdraft-class&lt;/A&gt; and the export, it is a property in the service definition draft you can set.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;sharing_draft.allowExporting = True&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This statement is convoluted:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;if shrOrg or shrEveryone or shrGroups:
    print("Setting sharing options…")
    fs.share(org=shrOrg, everyone=shrEveryone, groups=shrGroups)&lt;/LI-CODE&gt;&lt;P&gt;and is really saying as set:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;if True or False or 'DBYD':
    print("Setting sharing options…")
    fs.share(org=shrOrg, everyone=shrEveryone, groups=shrGroups)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;The conditional really isn't doing anything.&lt;/P&gt;&lt;P&gt;Check the example for sharing in the same featuresharingdraft docs- it uses an xml editor to edit the sddraft. Why it cant be an exposed property like the others when creating the sddraft is a mystery.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Change following to "true" to share
SharetoOrganization = "false"
SharetoEveryone = "true"
SharetoGroup = "false"
# If SharetoGroup is set to "true", uncomment line below and provide group IDs
GroupID = ""    # GroupID = "f07fab920d71339cb7b1291e3059b7a8, e0fb8fff410b1d7bae1992700567f54a"

# Each key has a corresponding value. In all the cases, value of key_list[i] is value_list[i].
for i in range(key_list.length):
    if key_list[i].firstChild.nodeValue == "PackageUnderMyOrg":
        value_list[i].firstChild.nodeValue = SharetoOrganization
    if key_list[i].firstChild.nodeValue == "PackageIsPublic":
        value_list[i].firstChild.nodeValue = SharetoEveryone
    if key_list[i].firstChild.nodeValue == "PackageShareGroups":
        value_list[i].firstChild.nodeValue = SharetoGroup
    if SharetoGroup == "true" and key_list[i].firstChild.nodeValue == "PackageGroupIDs":
        value_list[i].firstChild.nodeValue = GroupID

# Write to the .sddraft file
f = open(sddraft_output_filename, 'w')
docs.writexml(f)
f.close()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2023 13:06:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-an-arcgis-online-hosted-feature-layer-using/m-p/1299114#M67964</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2023-06-14T13:06:19Z</dc:date>
    </item>
    <item>
      <title>Re: Update an ArcGIS Online hosted feature layer using a Python Script</title>
      <link>https://community.esri.com/t5/python-questions/update-an-arcgis-online-hosted-feature-layer-using/m-p/1305220#M68077</link>
      <description>&lt;P&gt;Hi Jeff, thank you for your reply and advice. I'll have a closer look and let you know the result.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jul 2023 04:37:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-an-arcgis-online-hosted-feature-layer-using/m-p/1305220#M68077</guid>
      <dc:creator>crtownsend</dc:creator>
      <dc:date>2023-07-03T04:37:05Z</dc:date>
    </item>
  </channel>
</rss>

