Select to view content in your preferred language

Updating hosted layer doesn't work when referencing a different map

222
0
08-30-2022 03:07 PM
AlfredBaldenweck
MVP Regular Contributor

Hi all,

I'm trying to automate updating a hosted layer.

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.")

 

It works fine when  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 

AlfredBaldenweck_0-1661897111361.png

 

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?

Thanks!

0 Kudos
0 Replies