<?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 Updating hosted layer doesn't work when referencing a different map in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/updating-hosted-layer-doesn-t-work-when/m-p/1207927#M65443</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I'm trying to automate updating a hosted layer.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;arcpy.AddMessage("Beginning to update the web layers.")

aprx = arcpy.mp.ArcGISProject("CURRENT")
mapL= aprx.listMaps("Map")[0]

ahulay= mapL.listLayers("Ahupuaa_NAD83_PA11")[0]
mokulay= mapL.listLayers("Moku_NAD83_PA11")[0]
tmklay= mapL.listLayers("HawaiiCountyTMK_NAD83_PA11")[0]

draft= mapL.getWebLayerSharingDraft('HOSTING_SERVER',
                                    'FEATURE', 
                                    'KMS_File_Index', 
                                    [ahulay, mokulay, tmklay]) 
# Change its properties to allow it to Overwrite the existing layers.
draft.overwriteExistingService = True

draftaddress = r"K:\...File_Index.sddraft"

arcpy.AddMessage("Prepping to share as a weblayer")

draft.exportToSDDraft(draftaddress)
arcpy.server.StageService(draftaddress, 'KMS_File_Index.sd')

arcpy.AddMessage("Uploading weblayer")
arcpy.server.UploadServiceDefinition(r'KMS_File_Index.sd', 'HOSTING_SERVER')

arcpy.AddMessage("Successfully updated the KMS web layers.")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It works fine when&amp;nbsp; mapL is set to "Map" (Line 4), but when I added those same layers to a a new map (and saved) , then replace "Map" with the new name, it will run all the way through with no problems, but the updated web layer won't have anything in it&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AlfredBaldenweck_0-1661897111361.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/49866iC4B2A13B59224FFB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AlfredBaldenweck_0-1661897111361.png" alt="AlfredBaldenweck_0-1661897111361.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The only change I'm making to the code is the value in mapL. I'm not getting any index errors, so I 'm sure that everything else is right. Does anyone have any ideas as to how to fix this?&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Tue, 30 Aug 2022 22:07:30 GMT</pubDate>
    <dc:creator>AlfredBaldenweck</dc:creator>
    <dc:date>2022-08-30T22:07:30Z</dc:date>
    <item>
      <title>Updating hosted layer doesn't work when referencing a different map</title>
      <link>https://community.esri.com/t5/python-questions/updating-hosted-layer-doesn-t-work-when/m-p/1207927#M65443</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I'm trying to automate updating a hosted layer.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;arcpy.AddMessage("Beginning to update the web layers.")

aprx = arcpy.mp.ArcGISProject("CURRENT")
mapL= aprx.listMaps("Map")[0]

ahulay= mapL.listLayers("Ahupuaa_NAD83_PA11")[0]
mokulay= mapL.listLayers("Moku_NAD83_PA11")[0]
tmklay= mapL.listLayers("HawaiiCountyTMK_NAD83_PA11")[0]

draft= mapL.getWebLayerSharingDraft('HOSTING_SERVER',
                                    'FEATURE', 
                                    'KMS_File_Index', 
                                    [ahulay, mokulay, tmklay]) 
# Change its properties to allow it to Overwrite the existing layers.
draft.overwriteExistingService = True

draftaddress = r"K:\...File_Index.sddraft"

arcpy.AddMessage("Prepping to share as a weblayer")

draft.exportToSDDraft(draftaddress)
arcpy.server.StageService(draftaddress, 'KMS_File_Index.sd')

arcpy.AddMessage("Uploading weblayer")
arcpy.server.UploadServiceDefinition(r'KMS_File_Index.sd', 'HOSTING_SERVER')

arcpy.AddMessage("Successfully updated the KMS web layers.")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It works fine when&amp;nbsp; mapL is set to "Map" (Line 4), but when I added those same layers to a a new map (and saved) , then replace "Map" with the new name, it will run all the way through with no problems, but the updated web layer won't have anything in it&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AlfredBaldenweck_0-1661897111361.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/49866iC4B2A13B59224FFB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AlfredBaldenweck_0-1661897111361.png" alt="AlfredBaldenweck_0-1661897111361.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The only change I'm making to the code is the value in mapL. I'm not getting any index errors, so I 'm sure that everything else is right. Does anyone have any ideas as to how to fix this?&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 30 Aug 2022 22:07:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/updating-hosted-layer-doesn-t-work-when/m-p/1207927#M65443</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2022-08-30T22:07:30Z</dc:date>
    </item>
  </channel>
</rss>

