<?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 Copy Pop-ups Between Web Map Layers help (2.3 to 2.4 Update) in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/copy-pop-ups-between-web-map-layers-help-2-3-to-2/m-p/1560236#M10891</link>
    <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;&lt;P&gt;Over the past year or two I've been using an older script posted that copied popups &lt;A href="https://community.esri.com/t5/arcgis-online-blog/copy-pop-up-between-web-map-layers/ba-p/1073105" target="_self"&gt;between webmap layers&lt;/A&gt;. See the script below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;# This script assigns a pop up from one web map layer (source) to another web map layer (target).
# User to provide the following inputs:
    # web map 32-character id for both the source and target web map. If the layers are in the same webmap the id will be the same.
    # exact name of layer in source web map with existing popup to copy (source layer)
    # exact name of layer in target web map to which the popup will be assigned to (target layer)
    # ArcGIS Online credentials: url, username &amp;amp; password

### WARNING: THIS SCRIPT WILL COMPLETELY REMOVE THE EXISTING POPUP FROM THE TARGET LAYER AND ASSIGN IT WITH THE SOURCE LAYER POPUP ###
    
############## USER INPUTS ###################################################################
    
account = '' # AGOL/Portal url
username = '' # AGOL Username
password = '' # AGOL password
webmap_id_source = '' #  32-character id of web map with the source layer
webmap_id_target = '' #  32-character id of web map with the target layer 
copy_popup_from_this_layer = '' # insert the exact layer name as it is in the source webmap
paste_popup_to_this_layer = ''  # insert the exact layer name as it is in the target webmap

##############################################################################################

### EXECUTE ###

#Import
from arcgis.gis import GIS
from arcgis.mapping import WebMap
import sys

# Check layers names and web maps are not identical
if webmap_id_source == webmap_id_target and copy_popup_from_this_layer == paste_popup_to_this_layer:
    sys.exit("Script cancelled: Source and Target layers have the same name and are within the same web map. Please rename one layer before continuing")
    
#Connect to GIS
gis = GIS(account,username, password)
source_webmap = gis.content.get(webmap_id_source)
target_webmap = gis.content.get(webmap_id_target)

# Get web map and all its layers if the source and target layers are in different web maps. Define source and target layers.
if webmap_id_source != webmap_id_target:
    web_map_obj_source = WebMap(source_webmap)
    web_map_obj_target = WebMap(target_webmap)
    layers_sourceWM = web_map_obj_source.layers
    layers_targetWM = web_map_obj_target.layers
    source_layer = [i for i in layers_sourceWM if i.title == copy_popup_from_this_layer]
    target_layer = [i for i in layers_targetWM if i.title == paste_popup_to_this_layer]
   
# Get web map and all its layers if the source and target layers are in the same web map. Define source and target layers.
if webmap_id_source == webmap_id_target:
    web_map_obj_target = WebMap(source_webmap)
    layersWM = web_map_obj_target.layers
    source_layer = [i for i in layersWM if i.title == copy_popup_from_this_layer]
    target_layer = [i for i in layersWM if i.title == paste_popup_to_this_layer]

# Check there's one source or target layer with the same name in the map. If not, report and cancel script.
if len(source_layer) == 0:
    sys.exit("Script cancelled: source layer name doesn't exist in web map")
if len(target_layer) == 0:
    sys.exit("Script cancelled: target layer name doesn't exist in web map")
if len(source_layer) &amp;gt;1:
    sys.exit("Script cancelled: more than one layer in the web map has the source name. Not sure which one you want to copy the pop-up from! Please make sure the layer has a unique name (you can change it back after you run the script)")
if len(target_layer) &amp;gt;1:
    sys.exit("Script cancelled: more than one layer in the target web map has the target name. Not sure which one you want to copy the pop-up to! Please make sure the layer has a unique name (you can change it back after you run the script)")
    
# Paste the source popup to the target layer
target_layer[0].update({'popupInfo':source_layer[0].popupInfo})

# Update/save webmap
web_map_obj_target.update()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With the update from 2.3 to 2.4 it seems to have broken many parts of the code. I'm aware of the module and class change from arcgis.mapping/Webmap to arcgis.map/Map but I'm having issues with other parts of the code, such as the Webmap function and calling layers from these webmaps.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;if webmap_id_source != webmap_id_target:
    web_map_obj_source = WebMap(source_webmap)
    web_map_obj_target = WebMap(target_webmap)
    layers_sourceWM = web_map_obj_source.layers
    layers_targetWM = web_map_obj_target.layers
    source_layer = [i for i in layers_sourceWM if i.title == copy_popup_from_this_layer]
    target_layer = [i for i in layers_targetWM if i.title == paste_popup_to_this_layer]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've spent a bit trying to fix the script myself but I'm still fairly new to coding and haven't been able to figure it out. This script saves a massive amount of time, if anyone could help me out I'd greatly appreciate it!!&lt;/P&gt;</description>
    <pubDate>Tue, 19 Nov 2024 16:17:27 GMT</pubDate>
    <dc:creator>David_SumanHCCSD</dc:creator>
    <dc:date>2024-11-19T16:17:27Z</dc:date>
    <item>
      <title>Copy Pop-ups Between Web Map Layers help (2.3 to 2.4 Update)</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/copy-pop-ups-between-web-map-layers-help-2-3-to-2/m-p/1560236#M10891</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;&lt;P&gt;Over the past year or two I've been using an older script posted that copied popups &lt;A href="https://community.esri.com/t5/arcgis-online-blog/copy-pop-up-between-web-map-layers/ba-p/1073105" target="_self"&gt;between webmap layers&lt;/A&gt;. See the script below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;# This script assigns a pop up from one web map layer (source) to another web map layer (target).
# User to provide the following inputs:
    # web map 32-character id for both the source and target web map. If the layers are in the same webmap the id will be the same.
    # exact name of layer in source web map with existing popup to copy (source layer)
    # exact name of layer in target web map to which the popup will be assigned to (target layer)
    # ArcGIS Online credentials: url, username &amp;amp; password

### WARNING: THIS SCRIPT WILL COMPLETELY REMOVE THE EXISTING POPUP FROM THE TARGET LAYER AND ASSIGN IT WITH THE SOURCE LAYER POPUP ###
    
############## USER INPUTS ###################################################################
    
account = '' # AGOL/Portal url
username = '' # AGOL Username
password = '' # AGOL password
webmap_id_source = '' #  32-character id of web map with the source layer
webmap_id_target = '' #  32-character id of web map with the target layer 
copy_popup_from_this_layer = '' # insert the exact layer name as it is in the source webmap
paste_popup_to_this_layer = ''  # insert the exact layer name as it is in the target webmap

##############################################################################################

### EXECUTE ###

#Import
from arcgis.gis import GIS
from arcgis.mapping import WebMap
import sys

# Check layers names and web maps are not identical
if webmap_id_source == webmap_id_target and copy_popup_from_this_layer == paste_popup_to_this_layer:
    sys.exit("Script cancelled: Source and Target layers have the same name and are within the same web map. Please rename one layer before continuing")
    
#Connect to GIS
gis = GIS(account,username, password)
source_webmap = gis.content.get(webmap_id_source)
target_webmap = gis.content.get(webmap_id_target)

# Get web map and all its layers if the source and target layers are in different web maps. Define source and target layers.
if webmap_id_source != webmap_id_target:
    web_map_obj_source = WebMap(source_webmap)
    web_map_obj_target = WebMap(target_webmap)
    layers_sourceWM = web_map_obj_source.layers
    layers_targetWM = web_map_obj_target.layers
    source_layer = [i for i in layers_sourceWM if i.title == copy_popup_from_this_layer]
    target_layer = [i for i in layers_targetWM if i.title == paste_popup_to_this_layer]
   
# Get web map and all its layers if the source and target layers are in the same web map. Define source and target layers.
if webmap_id_source == webmap_id_target:
    web_map_obj_target = WebMap(source_webmap)
    layersWM = web_map_obj_target.layers
    source_layer = [i for i in layersWM if i.title == copy_popup_from_this_layer]
    target_layer = [i for i in layersWM if i.title == paste_popup_to_this_layer]

# Check there's one source or target layer with the same name in the map. If not, report and cancel script.
if len(source_layer) == 0:
    sys.exit("Script cancelled: source layer name doesn't exist in web map")
if len(target_layer) == 0:
    sys.exit("Script cancelled: target layer name doesn't exist in web map")
if len(source_layer) &amp;gt;1:
    sys.exit("Script cancelled: more than one layer in the web map has the source name. Not sure which one you want to copy the pop-up from! Please make sure the layer has a unique name (you can change it back after you run the script)")
if len(target_layer) &amp;gt;1:
    sys.exit("Script cancelled: more than one layer in the target web map has the target name. Not sure which one you want to copy the pop-up to! Please make sure the layer has a unique name (you can change it back after you run the script)")
    
# Paste the source popup to the target layer
target_layer[0].update({'popupInfo':source_layer[0].popupInfo})

# Update/save webmap
web_map_obj_target.update()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With the update from 2.3 to 2.4 it seems to have broken many parts of the code. I'm aware of the module and class change from arcgis.mapping/Webmap to arcgis.map/Map but I'm having issues with other parts of the code, such as the Webmap function and calling layers from these webmaps.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;if webmap_id_source != webmap_id_target:
    web_map_obj_source = WebMap(source_webmap)
    web_map_obj_target = WebMap(target_webmap)
    layers_sourceWM = web_map_obj_source.layers
    layers_targetWM = web_map_obj_target.layers
    source_layer = [i for i in layers_sourceWM if i.title == copy_popup_from_this_layer]
    target_layer = [i for i in layers_targetWM if i.title == paste_popup_to_this_layer]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've spent a bit trying to fix the script myself but I'm still fairly new to coding and haven't been able to figure it out. This script saves a massive amount of time, if anyone could help me out I'd greatly appreciate it!!&lt;/P&gt;</description>
      <pubDate>Tue, 19 Nov 2024 16:17:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/copy-pop-ups-between-web-map-layers-help-2-3-to-2/m-p/1560236#M10891</guid>
      <dc:creator>David_SumanHCCSD</dc:creator>
      <dc:date>2024-11-19T16:17:27Z</dc:date>
    </item>
    <item>
      <title>Re: Copy Pop-ups Between Web Map Layers help (2.3 to 2.4 Update)</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/copy-pop-ups-between-web-map-layers-help-2-3-to-2/m-p/1563765#M10920</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/556576"&gt;@David_SumanHCCSD&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Try the below. Each section is commented. No need to utilise WebMap (2.3.0) or Map (2.4.0) and just manipulate the JSON directly.&lt;/P&gt;&lt;P&gt;As always, test before implementing.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis.gis import GIS

## access AGOL
agol = GIS("home")

## the source and target layer names
source_layer_name = "SOURCE_LAYER_NAME"
target_layer_name = "TARGET_LAYER_NAME"

## get the source WebMap Item
source_wm_item = agol.content.get("SOURCE_WM_ID") # add Item ID
## get the source WebMap JSON definition
source_wm_data = source_wm_item.get_data()
## get the popupInfo definition from the source layer
popup_def = [lyr["popupInfo"] for lyr in source_wm_data["operationalLayers"] if lyr["title"] == source_layer_name][0]


## get the target WebMap Item
target_wm_item = agol.content.get("TARGET_WM_ID") # add Item ID
## get the target WebMap JSON definition
target_wm_data = target_wm_item.get_data()
## get the index in the operationalLayers that the target layer sits
target_lyr_index = [index for index, lyr in enumerate(target_wm_data["operationalLayers"]) if lyr["title"] == target_layer_name][0]

## update the target layer popupInfo definition
target_wm_data["operationalLayers"][target_lyr_index]["popupInfo"] = popup_def


## apply the update
item_properties = {"text" : target_wm_data}
target_wm_item.update(item_properties=item_properties)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All the best,&lt;/P&gt;&lt;P&gt;Glen&lt;/P&gt;</description>
      <pubDate>Mon, 02 Dec 2024 17:55:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/copy-pop-ups-between-web-map-layers-help-2-3-to-2/m-p/1563765#M10920</guid>
      <dc:creator>Clubdebambos</dc:creator>
      <dc:date>2024-12-02T17:55:14Z</dc:date>
    </item>
    <item>
      <title>Re: Copy Pop-ups Between Web Map Layers help (2.3 to 2.4 Update)</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/copy-pop-ups-between-web-map-layers-help-2-3-to-2/m-p/1564841#M10929</link>
      <description>&lt;P&gt;This worked perfectly, thank you very much!!&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2024 19:31:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/copy-pop-ups-between-web-map-layers-help-2-3-to-2/m-p/1564841#M10929</guid>
      <dc:creator>David_SumanHCCSD</dc:creator>
      <dc:date>2024-12-04T19:31:51Z</dc:date>
    </item>
  </channel>
</rss>

