Select to view content in your preferred language

clone_items() Behavior has changed

2413
9
Jump to solution
03-28-2023 02:18 AM
Labels (1)
JoeNunn
Frequent 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
2 Solutions

Accepted Solutions
ValGaj
by
Emerging 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 🙂

View solution in original post

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

9 Replies
JoeNunn
Frequent 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
Emerging 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
Frequent 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
Frequent 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
JeffGarcia
Emerging Contributor

Hi Peter,

I am curious how I can set which version of the ArcGIS API for Python for my enterprise? I am attempting to run the clone_items() function on a dashboard and when I run my script using jupyter notebooks(2.1.0.2) on my local machine, this works fine. However, I need to run this script using portal notebooks (2.1.0.3) and I now see KeyError: 'desktopView' when using the same script. I suspect this is due to API version differences. Could this be resolved by reverting ArcGIS API versions on my notebook server?

0 Kudos
PeterKnoop
MVP Regular Contributor

@JeffGarcia, if the error is indeed because of a difference in the ArcGIS API for Python version, then you can Create your own custom container image for your Notebook Server. You might also try an older Notebook runtime image that has a version of the API that works they way you expect it to (e.g., View available Python libraries.)

JoeNunn
Frequent Contributor

Hi @ValGaj -  I finally (a year or more later!) got an opportunity to use your approach as python 1.8.4 is no longer available on AGOL notebook (as far as i am aware).  It does work so thank you for providing this solution. To get it to work i have to clone all the layers first by cloning the initial map, then run the clone a second time on the webmap  with the item_mapping setup correctly now i have the new IDs, then delete the first cloned map. This is considerably more code to achieve the same effect.  I don't suppose you know of a simpler approach using this method?  

0 Kudos
ValGaj
by
Emerging Contributor

Hi @JoeNunn 

Glad to see my solution worked for you.

Unfortunately i do not know any better or faster approach. As long as the clone_items() property does not publish something but only clone an item, we need to publish items to the target portal and run the clone_item() property to do it correctly.

0 Kudos