Clone Dashboard with New Web Map: Other Widgets don't Update

08-23-2021 06:47 PM
New Contributor III

I am in the process of cloning a number of dashboards for several organizations. I have created new web maps that need to be included within the cloned dashboards. In other words, when I clone, I'm swapping out the web maps that were originally in the dashboards and replacing them with new web maps.

I'm able to clone the dashboard and replace the old maps with the new maps; however, all of the other widgets are broken when I run the clone process (i.e., I'm getting a Data Source Error and the widgets are not able to access the data):


To figure out the best way to run my clone operation, I watched the following video:

My code to try to get this working is here:

# import libraries
from arcgis.gis import GIS

# connect to GIS org
gis = GIS(url, username, password)

# get the dashboard to be cloned by item ID
dash = gis.content.get("6c698f1b477645c381ffda09b9dac0b8")
dash_name = dash.title

# get existing map widget item ID
dash_map = [w for w in dash.get_data()['widgets'] if w['type'] == 'mapWidget'][0]

# create Python dictionary object to hold the web map items ids for the old WM and the new WM
# Key - old web map item id
# Value - new web map item id (new web map item ID is hard coded for now)
wm_mapping = {dash_map['itemId']: '351fa7da899c491ba061692dc785259f'}

# clone the dashboard while substituting the new web map (wm_mapping VALUE) in for the old web map (wm_mapping KEY)
cloned_dash_item = gis.content.clone_items(items=[dash], folder="zz_ClonedAppsWithUpdatedWebMaps", item_mapping=wm_mapping)

print(f'finished cloning {dash_name} dashboard')


Is there something I'm missing? Do I need to include the other widgets in my item mapping dictionary (line 18)? I made sure that the name of the layers that "feed" the various widgets didn't change between the old and the new web maps in case that would cause the widgets to break.

Any help is appreciated.

Tags (2)
0 Kudos
2 Replies
New Contributor II

@pmccord did you ever manage to get this to work? I'm having the same issue with widgets not updating, as well as sometimes the map not actually updating.

0 Kudos
New Contributor III

Hi @abrown8 ,

You may need to update the widgets with data from the old maps. I was able to get this to work to some extent, but if I remember correctly, I still had to manually update a few things.


Please give the below a shot. Simply add the below code to the end of the above script (after line 22 above). You'll also need to import the json library 

import json

 at the beginning of your script.

Here's the code to add after line 22:

cloned_dash_data = cloned_dash_item.get_data()
# swap old layer source with new layer source
for widget in cloned_dash_data["widgets"]:
    if "datasets" in widget:
        widget["datasets"][0]["dataSource"]["layerId"] = new_lyr_src

# udpate item
cloned_dash_item.update(item_properties={"text": json.dumps(cloned_dash_data)})

print(f"finished cloning {dash_name} dashboard")