Copying an AGO item to different user

1576
7
Jump to solution
01-11-2021 10:12 AM
BrittaneyHarkness
New Contributor III

Hi there, I'm in the process of copying web maps from one user to another. I chose to copy the item rather than clone_items after getting an error stating that a feature service the web map was consuming could not be cloned. Copying worked just fine and the web map references the source URLS. My question is, is the copied item completely isolated from the source item? I want to move on to make some updates  a few of the service urls for some of the operational layers but I want to confirm that this will not effect the source item.

 

Thanks!

0 Kudos
1 Solution

Accepted Solutions
simoxu
by MVP Regular Contributor
MVP Regular Contributor

If item mapping does not work for your cloned story map, then try to use AGOL Assistant to replace it manually.

If you want a non-interactive scripting experience, you can use get_data() of the item to get the JSON or text of the item and change them programmatically, then use update() function of the item to save the change.

I encounter the same issue when I was cloning an very old story map to another portal, I ended up using this semi-automatic approach 

View solution in original post

7 Replies
by Anonymous User
Not applicable

Hi Brittaney. 

What method did you use to copy the items? If you used arcgis.gis.Item.copy, then the following applies:

"For layers, copy will create a new item that uses the URL as a reference. For non-layer based items, these will be copied and the exact same data will be provided."

If you want to create new, non-dependent layers, then the arcgis.gis.ContentManager.clone_items method is your best bet.

"Clone content to the GIS by creating new items."

If you go this route, be sure to preserve the relationship between different items (e.g. feature layers in a web map) by following the example outlined here.

An easy way to see if an item you cloned/copied is separate from the original is to go the Item Details page and scroll down to view the URL of the item. If the URLs are the same, then they are in fact the same item.

-Calvin

0 Kudos
BrittaneyHarkness
New Contributor III

HI Calvin,

I used the item.copy method to make a copy of webmaps. I wanted to keep the references to services so I could update the service urls later. That worked fine. 

I'm in the process now of cloning web mapping applications and dashboards right now using the ContentManager.clone_items method because I want to now clone those apps and pass the new web map ids that I copied to the cloned app. I'm running into a problem though with the item mapping. I have tried several times to pass the item_mapping parameter the dictionary of source (old web map ids) and target (new web map ids) but the result is a clone of the app with the old web maps: here is my code below. You can see that the ids for the web maps persist rather than updating to the new ids. 

This is a StoryMap app

item_map = {'2fa027839c63473094f538d029a17f17': '4301017941324b35b157f54114877481', 'dd161c2a532a491987426ec3912840d8': '7ff1b8c0c2a04b5992893bda146f6ef2'}

copied_embedded_app = content_manager.clone_items([embedded_app], folder_name, item_mapping = item_map)
print_app_inventory(copied_embedded_app[0], gis_source)

BrittaneyHarkness_0-1610557842414.png

 

 

0 Kudos
by Anonymous User
Not applicable

Without knowing too much about what's going on in your code, did you run through the section "Establish relationship between items" in the above link? It looks like the items copied, but you haven't yet mapped the output to use the new related items string. 

The above example has this:

 

for key in source_target_itemId_map.keys():
    source_item = source_items_by_id[key]
    target_itemid = source_target_itemId_map[key]
    target_item = target.content.get(target_itemid)

    print(source_item.title + " # " + source_item.type)
    for relationship in RELATIONSHIP_TYPES:
        try:
            source_related_items = source_item.related_items(relationship)
            for source_related_item in source_related_items:
                print("\t\t" + source_related_item.title + " # " + 
                      source_related_item.type +"\t## " + relationship)

                #establish same relationship amongst target items
                print("\t\t" + "establishing relationship in target portal", end=" ")
                target_related_itemid = source_target_itemId_map[source_related_item.itemid]
                target_related_item = target.content.get(target_related_itemid)
                status = target_item.add_relationship(target_related_item, relationship)
                print(str(status))
        except Exception as rel_ex:
            print("\t\t Error when checking for " + relationship + " : " + str(rel_ex))
            continue

 

 

 

0 Kudos
BrittaneyHarkness
New Contributor III

Hey Calvin,

Thanks for responding again. I was actually following this guide:https://developers.arcgis.com/python/guide/cloning-content/#the-cloning-process because I need to make sure that the cloned applications were consuming the right web app. I took a look at the relationship process, but it looks like that more for establishing relationships between services and web map or web applications. 

0 Kudos
simoxu
by MVP Regular Contributor
MVP Regular Contributor

If item mapping does not work for your cloned story map, then try to use AGOL Assistant to replace it manually.

If you want a non-interactive scripting experience, you can use get_data() of the item to get the JSON or text of the item and change them programmatically, then use update() function of the item to save the change.

I encounter the same issue when I was cloning an very old story map to another portal, I ended up using this semi-automatic approach 

BrittaneyHarkness
New Contributor III

Hi Simon, thanks for your response. I ended up doing the get_data() option for some of the older stormaps and that seemed to do the trick. In addition to that I also had success using the get_data() method to find the dependencies of my apps and clone those first then clone the actual app and pass the item_id_map to the clone items method. That seemed to work. 

simoxu
by MVP Regular Contributor
MVP Regular Contributor

Hi Brittaney, thanks for sharing your solution.

Yes it is trickier for those older story maps, I guess the reason is their data structures are different from the latest ones.