AnsweredAssumed Answered

Copy operational layers object from one web map to another

Question asked by jay.gregory on May 29, 2018
Latest reply on May 30, 2018 by AMani-esristaff

I would like to use ArcGIS Python API (v. 1.4.1) to copy the operational layers from one map to another in the same 10.6 Portal (for a development map / production map environment where I make changes to the development maps' symbology, layers, popups, etc., and then just copy the entire operational layers object to the production map), but I can't get it to work (even though it worked on a previous version of the API / previous version of Portal).  


Here is my old code, which worked in a previous version.

In this version, the code successfully runs, but the destination map isn't changed.

from arcgis.gis import GIS
from arcgis.gis import Item
import arcgis.mapping

portal = GIS("https://portalurl/webcontext", "username","password", verify_cert=False)
srcMap = Item(portal, "5959197ba01748ccb51cf097597b4cf4")
destMap= Item(portal,"e326e343d5aa45668a448e54acc4d06d")
opsLayers = srcMap.get_data()['operationalLayers']
mapDestObj = arcgis.mapping.WebMap(destMap)
mapDestObj['operationalLayers'] = opsLayers


I've also followed instructions located at Using and updating GIS content | ArcGIS for Developers , but that doesn't seem to work either.  

mapDestObj has a layers attribute, but mapDestObj.layers = opsLayers throws an AttributeError (can't set attribute)


I've also tried the following: which successfully updates the mapDestObj.layers attribute, but doesn't save the map when I run the update command.  

for index, layer in enumerate(mapDestObj.layers):
    mapDestObj.layers[index] = opsLayers[index]


Does anyone have a working prototype for this workflow?