<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Unable to clone layer in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-clone-layer/m-p/1296441#M8756</link>
    <description>&lt;P&gt;-Goal: I am trying to create a script to access a layer on portal and clone it. After cloning it I would like to overwrite a layer in either a SQL database or back in portal.&amp;nbsp;&lt;/P&gt;&lt;P&gt;-Reason: As the original layer updates I would like to run the script to update the copy in which I have view layers created from.&lt;/P&gt;&lt;P&gt;-What I have tried: I have tried a multitude of things, but have not found a way to clone the layer without hitting a type error or a way to save the layer in a SQL DB or portal.&lt;/P&gt;&lt;P&gt;-Here is some code and errors for creating a clone:&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;LI-CODE lang="python"&gt;source_layer = gis.content.search(source_layer_name, item_type="Feature Layer")[0]
temporary_copy = ContentManager.clone_items(source_layer)

Traceback (most recent call last):
File "&amp;lt;string&amp;gt;", line 1, in &amp;lt;module&amp;gt;
TypeError: clone_items() missing 1 required positional argument: 'items'


temporary_copy = ContentManager.clone_items(items=source_layer)

Traceback (most recent call last):
File "&amp;lt;string&amp;gt;", line 1, in &amp;lt;module&amp;gt;
TypeError: clone_items() missing 1 required positional argument: 'self'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-For saving the layer I have really only tried publish(), but it doesn't seem to take a layer as an input.&lt;/P&gt;&lt;P&gt;How do you save a layer in portal? in a SQL DB? using arcgis api for python?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-Here is what the entire script I have been working with:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def overwrite_existing_layer(source_layer_name, sql_database, layer_name):
    try:

  
        # Connect to the ArcGIS Portal
        gis = GIS('pro')
        portal_dstore = gis.datastore


        # Retrieve the feature layer you want to clone
        source_layer = gis.content.search(source_layer_name, item_type="Feature Layer")[0]
        
        # Create a temporary copy of the layer or use clone_item() shown above
        temporary_copy = source_layer.layers[0].query()
        
        # Save the temporary copy to overwrite the existing layer in the SQL database
        temporary_copy.publish()

        print("Temporary copy overwritten in SQL database.")

        # Delete the temporary copy
        # portal_dstore.delete_layers(temporary_copy)

        # if not temporary_copy.exists:
        #     print("Temporary copy deleted.") 
        
        print('Finished running script')

    except Exception as e:
        # Handle any errors that occur during the process
        print(f"An error occurred: {str(e)}")&lt;/LI-CODE&gt;&lt;P&gt;-Any and all advice is appreciated. I'm pretty new to using python within the ArcGIS suite. I have not found the esri documentation very useful so if there is any other recommended resources, those would be appreciated!&lt;/P&gt;</description>
    <pubDate>Tue, 06 Jun 2023 19:24:03 GMT</pubDate>
    <dc:creator>ZacharyKasson</dc:creator>
    <dc:date>2023-06-06T19:24:03Z</dc:date>
    <item>
      <title>Unable to clone layer</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-clone-layer/m-p/1296441#M8756</link>
      <description>&lt;P&gt;-Goal: I am trying to create a script to access a layer on portal and clone it. After cloning it I would like to overwrite a layer in either a SQL database or back in portal.&amp;nbsp;&lt;/P&gt;&lt;P&gt;-Reason: As the original layer updates I would like to run the script to update the copy in which I have view layers created from.&lt;/P&gt;&lt;P&gt;-What I have tried: I have tried a multitude of things, but have not found a way to clone the layer without hitting a type error or a way to save the layer in a SQL DB or portal.&lt;/P&gt;&lt;P&gt;-Here is some code and errors for creating a clone:&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;LI-CODE lang="python"&gt;source_layer = gis.content.search(source_layer_name, item_type="Feature Layer")[0]
temporary_copy = ContentManager.clone_items(source_layer)

Traceback (most recent call last):
File "&amp;lt;string&amp;gt;", line 1, in &amp;lt;module&amp;gt;
TypeError: clone_items() missing 1 required positional argument: 'items'


temporary_copy = ContentManager.clone_items(items=source_layer)

Traceback (most recent call last):
File "&amp;lt;string&amp;gt;", line 1, in &amp;lt;module&amp;gt;
TypeError: clone_items() missing 1 required positional argument: 'self'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-For saving the layer I have really only tried publish(), but it doesn't seem to take a layer as an input.&lt;/P&gt;&lt;P&gt;How do you save a layer in portal? in a SQL DB? using arcgis api for python?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-Here is what the entire script I have been working with:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def overwrite_existing_layer(source_layer_name, sql_database, layer_name):
    try:

  
        # Connect to the ArcGIS Portal
        gis = GIS('pro')
        portal_dstore = gis.datastore


        # Retrieve the feature layer you want to clone
        source_layer = gis.content.search(source_layer_name, item_type="Feature Layer")[0]
        
        # Create a temporary copy of the layer or use clone_item() shown above
        temporary_copy = source_layer.layers[0].query()
        
        # Save the temporary copy to overwrite the existing layer in the SQL database
        temporary_copy.publish()

        print("Temporary copy overwritten in SQL database.")

        # Delete the temporary copy
        # portal_dstore.delete_layers(temporary_copy)

        # if not temporary_copy.exists:
        #     print("Temporary copy deleted.") 
        
        print('Finished running script')

    except Exception as e:
        # Handle any errors that occur during the process
        print(f"An error occurred: {str(e)}")&lt;/LI-CODE&gt;&lt;P&gt;-Any and all advice is appreciated. I'm pretty new to using python within the ArcGIS suite. I have not found the esri documentation very useful so if there is any other recommended resources, those would be appreciated!&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2023 19:24:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-clone-layer/m-p/1296441#M8756</guid>
      <dc:creator>ZacharyKasson</dc:creator>
      <dc:date>2023-06-06T19:24:03Z</dc:date>
    </item>
  </channel>
</rss>

