Select to view content in your preferred language

Experience Builder Clone function fails in subfunction _clone_dict *FIX*

558
0
12-11-2023 06:39 AM
Labels (2)
BijanTaheri
Occasional Contributor

This is regarding cloning an ExB application using the new (version 2.2.0.1) ArcGIS API for Python submodule expbuilder in the apps module.

It is a great addition to the cloning library, but i found an error when cloning an ExB application which has widgets with no item id or no portal url. The function calls for the "portalUrl" and the "itemId" to be changed, but if those keys don't exist in the dict (widget in this case), the functions fails.

File: "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\apps\expbuilder\expbuilder.py"

Function: _clone_dict

Starts at line 756

 

I propose adding 2 IF statements, that checks if the data dictionary contains the relevant keys, that the function changes.

The final function will look like this:

def _clone_dict(data_dict, source, target, owner, **kwargs):
    """
    Helper function to clone items and update appropriate dict
    """
    new_dict = data_dict
    new_dict["attributes"]["portalUrl"] = target.url
    for k, v in new_dict["dataSources"].items():
        if "portalUrl" in v.keys(): #NEW LINE
            v["portalUrl"] = target.url

        if "itemId" in v.keys(): #NEW LINE
            item = source.content.get(v["itemId"])
            clone_result = target.content.clone_items([item], owner=owner, **kwargs)
            if clone_result:
                v["itemId"] = clone_result[0].itemid
            else:
                targ_item = target.content.search(item.title)[0]
                v["itemId"] = targ_item.itemid

    return new_dict
0 Replies