Select to view content in your preferred language

Changing the data source

146
2
2 weeks ago
Labels (1)
SLouq
by MVP Alum
MVP Alum

How do you change the web map a dashboard references? Do I need to add the web map as a new element to the dashboard? 

I have a dashboard I created a last year which references a web map to track assessments which is linked to Survey123. I recreated the Survey123 form so it is a newer version and want to reference it in my dashboard but can't remember how I changed the data source to show the new assessment web map in the dashboard.

Can someone help me out?

Tags (2)
0 Kudos
2 Replies
KimOllivier
Honored Contributor

In short you can't! Well it is not supported in the interactive interface. There is now an unsupported workaround provided by the Esri consulting team using the AGOL Assistant where you can do a search and replace for the item ID. If you know the Item IDs..... (Just do a search for AGOL Assistant and log in again).

Maybe you can find the Item IDs (the new one is easy enough from the new webmap and you may have the old webmap. If you have a new feature layer then create a new web map that references the new featurelayer otherwise you will have to do two updates, one for the webmap and another for the featurelayer.

I wrote a short python script to recursively look through the dashboard to find all Item IDs in the dashboard. I am intending to do the update too but haven't finished it yet.


# dashboard references 2
from arcgis.gis import GIS
import json
import sys
import arcpy
import os
os.getcwd
gis = GIS(profile='econet')

# Step 2: Get the Dashboard Item
try:
    dashboard_id = sys.argv[1]
except IndexError:
    # dashboard_id = "0f3670488cfc4ea19f4a8e22252979fd"  # RHB Trapping dashboard
    dashboard_id = "eafa864b127242b29b0f5d08fc20e017"  # PFK Trapping dashboard
dashboard_item = gis.content.get(dashboard_id)

if not dashboard_item:
    arcpy.AddMessage("Dashboard not found. Check the dashboard ID.")
    exit()
arcpy.AddMessage(f"<{dashboard_item.title}> found")

# Step 3: Access Dashboard's Configuration JSON (Data Block)
dashboard_data = dashboard_item.get_data()

if not dashboard_data:
    arcpy.AddMessage("No data block found in the dashboard.")
    exit()

# Step 4: Recursive Function to Extract Item IDs
def extract_item_ids(data, referenced_items):
    if isinstance(data, dict):
        for key, value in data.items():
            if key == "itemId":  # Check for itemId fields
                referenced_items.append(value)
            else:
                extract_item_ids(value, referenced_items)  # Recursively check nested dictionaries
    elif isinstance(data, list):
        for item in data:
            extract_item_ids(item, referenced_items)  # Recursively check nested lists

# Initialize a list to store referenced IDs
referenced_items = []
extract_item_ids(dashboard_data, referenced_items)

# Step 5: Fetch Referenced Item Details
unique_item_ids = set(referenced_items)  # Remove duplicates
item_details = []

for item_id in unique_item_ids:
    item = gis.content.get(item_id)
    if item:
        item_details.append({
            "Item ID": item_id,
            "Title": item.title,
            "Type": item.type
        })

# Step 6: Output Results
if item_details:
    arcpy.AddMessage("Referenced Items:")
    for item in item_details:
        arcpy.AddMessage(f"Item ID: {item['Item ID']}, Title: {item['Title']}, Type: {item['Type']}")
else:
    arcpy.AddMessage("No referenced items found in the dashboard.")

# Optional: Save to CSV
import pandas as pd
df = pd.DataFrame(item_details)
df.to_csv("referenced_items.csv", index=False)
arcpy.AddMessage("Referenced items saved to referenced_items.csv")
arcpy.AddMessage(f"{os.getcwd()}")​
0 Kudos
KimOllivier
Honored Contributor

If you just try to edit the dashboard and replace the source all settings will be lost so you have to rebuild the dashboard from scratch.

0 Kudos