Select to view content in your preferred language

Non-Buggy Way to Duplicate Hosted Feature Service?

814
4
12-01-2023 08:01 AM
SH_DH
by
Emerging Contributor

I have a script I use to create groups, create new layers based off existing template hosted feature layers, set up a webmap, and share with my organization.  I have been successfully using copy_feature_layer_collection, however I want to update my template hosted feature layer to have related tables. copy_feature_layer_collection technically should support that, but there's been a handful of threads showing there are bugs preventing it from working.

cloned_flyr = hosted_flyr.copy_feature_layer_collection('{} Observations'.format(project_number), layers = [0, 1, 2]) 

 

I've played around with clone_items, which should also work for this application, however it does nothing. I have entered it directly into the Python window in Pro and it and runs for a few seconds, then returns an empty list without an error. An empty hosted feature service is created in ArcGIS Online but absent of any layers.

cloned_flyr = gis.content.clone_items(items = [hosted_flyr], folder = '{}'.format(project_title) , copy_data = True, copy_global_ids = False, preserve_item_id = False)

 

Anything I'm missing here, or any other commands I should try? copy() seems to duplicate the item but still points to the original hosted feature layer URL, so that won't fit the bill.

0 Kudos
4 Replies
David_McRitchie
Esri Contributor

For the clone_items method are you doing this between two portals? The documentation discusses that it is a workflow for use from one portal to another.

Many thanks,

David

Esri UK -Technical Support Analyst
SH_DH
by
Emerging Contributor

Yes, these are taking place all within the same portal.

0 Kudos
EarlMedina
Esri Regular Contributor

As far as I can tell, everything seems to be in order. It's not really advertised, but you can do same-portal clones (I used to do this quite a bit for similar reasons). Some other things you can try are exporting the data or creating a replica. From there, you can prepare the data as you wish locally and then publish as usual. If it fails to do either one of those, maybe there will be an error that provides more insight.

PeterHodkinson
Esri Contributor

Hi @SH_DH

I wonder whether the layers within your new feature service may be empty because clone_items() detects that they have already been cloned previously within your portal?

This section of the documentation describes this - https://developers.arcgis.com/python/guide/cloning-content/#the-cloning-process

PeterHodkinson_0-1712836410171.png

To workaround this you could set the parameter search_existing_items=False within clone_items()