clone_items() Behavior has changed

1187
5
Jump to solution
03-28-2023 02:18 AM
Labels (1)
JoeNunn
Occasional Contributor

Hi, I have previously succeeded in running a python script (set up as a tool in ArcGIS pro) that cloned an app (in this case the attachment viewer) and all  it content which was a map and the layers within the map. It previously functioned perfectly, however a change (earlier this year) has occurred where all the items are cloned (inc a new set of layers), however the layers in the map are still pointing back to the original layers.  A diagram below explains:

Current template:   Orig App >Orig Map >Orig Layers

What should happen after cloning: New App  > New Map > New Layers

What happens after cloning: New App  > New Map > Orig Layers

The line of script looks like this:

appToClone = gis.content.get('xxxxxxxxxxxxxxxxxxxxx')
layerList = [appToClone]
clonedLyrs = gis.content.clone_items(layerList, folder=folderName, copy_data=False, search_existing_items=False)

Any ideas why this is occurring?

Many thanks

Joe

0 Kudos
1 Solution

Accepted Solutions
PeterKnoop
MVP Regular Contributor

The environments you are using in ArcGIS Pro and Online are likely configured with different versions of the ArcGIS API for Python. You can check the version by running this in a notebook cell:

import arcgis
arcgis.__version__

I've found that for some cloning tasks, I get the best results if I use version 1.8.4 of the API. It seems to have gotten a lot buggier for some things after that, but also added new things that are in 1.8.4, so you may want to experiment as to which version works best for you desired workflow.

In Pro, you can set up your own environment with your desired version of the API, while in Online you can choose the different runtime versions to get different versions of the API. For example, version 5.0 of the ArcGIS Notebook Runtimes in Online contain version 1.8.4 of the API.

 

View solution in original post

5 Replies
JoeNunn
Occasional Contributor

To add to the above - I tested it on the AGOL notebook (the prev one is run in a script in ArcGIS Pro) and it works as it should ie the map is now pointing towards the new cloned layers.  

0 Kudos
ValGaj
by
New Contributor

Hello,

Glad to see i'm not the only one who wants to clone a Web Application with the ArcGIS API for Python.

Anyway, the thing with the clone_items() method its only clone the item but doesn't create one. Thus when a layer is cloned, its still pointing to the original one because clone_items() doesn't publish something.

To solve this, all the items your web app is dependent to (web map, layers and even widgets), needs to be publisheb on your target portal.

In your case, you just have to associate ids of your webmap.

Once done, you can use the item_mapping parameter inside clone_items() method to assignate the ids. Thus before using clone_items() you should have something like that :

webmap_item_mapping = {wm_source_id: wm_target_id}

 And use it like this :

portal_target.content.clone_items(items[webmap_item],
item_mapping=webmap_item_mapping, 
search_existing_items=True)

 

Hope it can help you, tell me if it works 🙂

JoeNunn
Occasional Contributor

Thanks for the advice there - What I find is that if I run it through AGOL notebook it does actually create clones that are not linked to the original (this is what I want), and links to those clones though?  Why does it give different results if run through Pro or on AGOL?

0 Kudos
PeterKnoop
MVP Regular Contributor

The environments you are using in ArcGIS Pro and Online are likely configured with different versions of the ArcGIS API for Python. You can check the version by running this in a notebook cell:

import arcgis
arcgis.__version__

I've found that for some cloning tasks, I get the best results if I use version 1.8.4 of the API. It seems to have gotten a lot buggier for some things after that, but also added new things that are in 1.8.4, so you may want to experiment as to which version works best for you desired workflow.

In Pro, you can set up your own environment with your desired version of the API, while in Online you can choose the different runtime versions to get different versions of the API. For example, version 5.0 of the ArcGIS Notebook Runtimes in Online contain version 1.8.4 of the API.

 

JoeNunn
Occasional Contributor

Ah yes that will be it!  Pro is using 2.0.1 and Online uses 1.8.4.  I can work from that - thank you!

0 Kudos