<?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 Re: Sharing after using clone_items() in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/sharing-after-using-clone-items/m-p/1013830#M5389</link>
    <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/426514"&gt;@Alex_Gole&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;No it doesn't.&lt;/P&gt;&lt;P&gt;These are the steps required for items to be cloned properly:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT size="5"&gt;&lt;STRONG&gt;Items&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;Copying items consists of multiple steps as explained in the following section of the sample:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;For each user create a mapping of itemId to the Item&lt;/LI&gt;&lt;LI&gt;Prepare sharing information for each item&lt;BR /&gt;Print a mapping of item and its group membership&lt;/LI&gt;&lt;LI&gt;Copy items one by one&lt;/LI&gt;&lt;LI&gt;Establish relationship between items&lt;/LI&gt;&lt;/OL&gt;</description>
    <pubDate>Tue, 05 Jan 2021 01:40:09 GMT</pubDate>
    <dc:creator>MehdiPira1</dc:creator>
    <dc:date>2021-01-05T01:40:09Z</dc:date>
    <item>
      <title>Sharing after using clone_items()</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/sharing-after-using-clone-items/m-p/1012963#M5369</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am in the process of migrating a Portal to another portal. I am using the clone_item() function to migrate the items unlike this &lt;A title="clone users, groups, and content" href="https://developers.arcgis.com/python/sample-notebooks/clone-portal-users-groups-and-content/" target="_self"&gt;clone users, groups, and content&lt;/A&gt;&amp;nbsp;. This works great. The only issue I have is when I try to share items with groups, org or everyone. Although my script does update the sharing for some, I often get this error&amp;nbsp;&lt;STRONG&gt;Item has a Relationship Type that does not allow this.&amp;nbsp;&lt;/STRONG&gt;&lt;STRONG&gt;(Error Code: 500)&lt;/STRONG&gt;.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any idea what I can do to update sharing for an item and its related items?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my current code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;#source content
source_users = source.users.search('!esri_ &amp;amp; !admin')

#target content
target_users = target.users.search('!esri_ &amp;amp; !admin &amp;amp; !system_publisher')


#source groups
source_groups = source.groups.search("!owner:esri_* &amp;amp; !Basemaps")

#target groups
target_groups = target.groups.search("!owner:esri_* &amp;amp; !Basemaps")



for user in source_users:
    if user.username == "ITPublisher1":
        tester_content = source.content.search("owner:"+ user.username, max_items=500)
        for item in tester_content:
            print(item.access)
 
            if item.access == "shared":
                for group in source_groups:
                    for group_item in group.content():
                        if group_item.itemid == item.itemid:
                            print(group)
                            target_group = target.groups.search(group.title)
                            for tg in target_group:
                                target_item = target.content.search(item.title)
                                print(tg.groupid)
                                for ti in target_item:
                                    print(ti)
                                    ti.share(everyone=False, org=False, groups=tg.groupid)
                        else:
                            print("not in target portal ")


           

            #elif item.access == "public":
            #    target_item = target.content.search(item.title)
            #    for ti in target_item:
            #        print(ti)
            #        ti.share(everyone=True, org=False)


            elif item.access == "org":
                target_item = target.content.search(item.title)
                for ti in target_item:
                    print(ti)
                    ti.share(everyone=False, org=True)
             &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Dec 2020 17:15:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/sharing-after-using-clone-items/m-p/1012963#M5369</guid>
      <dc:creator>Alex_Gole</dc:creator>
      <dc:date>2020-12-30T17:15:28Z</dc:date>
    </item>
    <item>
      <title>Re: Sharing after using clone_items()</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/sharing-after-using-clone-items/m-p/1013480#M5376</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/426514"&gt;@Alex_Gole&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;One of the requirements of cloning is establishing the same relationship between source and target items.&lt;/P&gt;&lt;P&gt;The following link provides a useful step by step process of establishing relationships when cloning (section:&amp;nbsp;&lt;STRONG&gt;Establish relationship between items&lt;/STRONG&gt;);&lt;/P&gt;&lt;P&gt;&lt;A title="Establish relationship between items" href="https://developers.arcgis.com/python/sample-notebooks/clone-portal-users-groups-and-content/#establish-relationship-between-items" target="_blank" rel="noopener"&gt;https://developers.arcgis.com/python/sample-notebooks/clone-portal-users-groups-and-content/#establish-relationship-between-items&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jan 2021 01:21:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/sharing-after-using-clone-items/m-p/1013480#M5376</guid>
      <dc:creator>MehdiPira1</dc:creator>
      <dc:date>2021-01-04T01:21:59Z</dc:date>
    </item>
    <item>
      <title>Re: Sharing after using clone_items()</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/sharing-after-using-clone-items/m-p/1013624#M5386</link>
      <description>&lt;P&gt;Doesn't&amp;nbsp;&lt;A title="clone_item()" href="https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#user" target="_self"&gt;clone_items()&lt;/A&gt;. Take care of the relationship. In the demo you point to, I notice that they dont use clone_items() when they copy&amp;nbsp; the items. they use:&lt;/P&gt;&lt;P&gt;what i use:&lt;/P&gt;&lt;P&gt;cloned_items = target.content.clone_items(items=[item], folder=f['title'], copy_data=False, group_mapping)&lt;/P&gt;&lt;P&gt;what is used by the sample:&lt;/P&gt;&lt;PRE&gt; &lt;SPAN class="n"&gt;target_item&lt;/SPAN&gt; &lt;SPAN class="o"&gt;=&lt;/SPAN&gt; &lt;SPAN class="n"&gt;target&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;content&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;add&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="n"&gt;item_properties&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt; &lt;SPAN class="n"&gt;data_file&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt; &lt;SPAN class="n"&gt;thumbnail_file&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt; 
                                             &lt;SPAN class="n"&gt;metadata_file&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt; &lt;SPAN class="n"&gt;source_item&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;owner&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt; &lt;SPAN class="n"&gt;folder_name&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;It looked like the relationship between items was taken care of by clone_items().&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jan 2021 16:43:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/sharing-after-using-clone-items/m-p/1013624#M5386</guid>
      <dc:creator>Alex_Gole</dc:creator>
      <dc:date>2021-01-04T16:43:14Z</dc:date>
    </item>
    <item>
      <title>Re: Sharing after using clone_items()</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/sharing-after-using-clone-items/m-p/1013830#M5389</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/426514"&gt;@Alex_Gole&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;No it doesn't.&lt;/P&gt;&lt;P&gt;These are the steps required for items to be cloned properly:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT size="5"&gt;&lt;STRONG&gt;Items&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;Copying items consists of multiple steps as explained in the following section of the sample:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;For each user create a mapping of itemId to the Item&lt;/LI&gt;&lt;LI&gt;Prepare sharing information for each item&lt;BR /&gt;Print a mapping of item and its group membership&lt;/LI&gt;&lt;LI&gt;Copy items one by one&lt;/LI&gt;&lt;LI&gt;Establish relationship between items&lt;/LI&gt;&lt;/OL&gt;</description>
      <pubDate>Tue, 05 Jan 2021 01:40:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/sharing-after-using-clone-items/m-p/1013830#M5389</guid>
      <dc:creator>MehdiPira1</dc:creator>
      <dc:date>2021-01-05T01:40:09Z</dc:date>
    </item>
    <item>
      <title>Re: Sharing after using clone_items()</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/sharing-after-using-clone-items/m-p/1013979#M5391</link>
      <description>&lt;P&gt;OK thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jan 2021 16:01:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/sharing-after-using-clone-items/m-p/1013979#M5391</guid>
      <dc:creator>Alex_Gole</dc:creator>
      <dc:date>2021-01-05T16:01:55Z</dc:date>
    </item>
  </channel>
</rss>

