<?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-uploading feature classes with attachment tables in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/re-uploading-feature-classes-with-attachment/m-p/1195093#M57642</link>
    <description>&lt;P&gt;Hi all, I came across this issue and was wondering if anyone else had it.&lt;/P&gt;&lt;P&gt;On Pro 2.9:&lt;/P&gt;&lt;P&gt;I'm trying to consolidate some feature services. Since that isn't possible (Please vote for relevant ideas &lt;A href="https://community.esri.com/t5/arcgis-online-ideas/combine-hosted-feature-layers/idc-p/1194719" target="_blank" rel="noopener"&gt;here&lt;/A&gt; and &lt;A href="https://community.esri.com/t5/arcgis-online-ideas/add-new-feature-classes-to-hosted-feature-layers/idi-p/1163140/jump-to/first-unread-message" target="_blank" rel="noopener"&gt;here&lt;/A&gt;), I've resorted to downloading all of them to a local gdb and then republishing them as one service.&lt;/P&gt;&lt;P&gt;This normally works, but I found that if a feature class with an attachment table was included, the process would fail. Testing shows that it doesn't occur when publishing a feature class/attachment table that was created locally; it's specifically those that were previously hosted.&lt;/P&gt;&lt;P&gt;This behaviour occurs regardless of the original feature service, and regardless of the number of them included.&lt;/P&gt;&lt;P&gt;I deleted the relationship classes and everything worked; I was able to upload the feature classes and their attachment tables just fine.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Has anyone else had this problem? &lt;/STRONG&gt;If so, I'd like to log a bug report.&lt;/P&gt;&lt;P&gt;I was able to restore the relationships in the feature service.&amp;nbsp;&lt;BR /&gt;A large amount of this method was taken from&amp;nbsp;@ Clubdebambos's great blog post about combining feature services&amp;nbsp;&lt;A href="https://community.esri.com/t5/arcgis-api-for-python-blog/add-table-from-hosted-service-to-another-and/bc-p/1190303#M112" target="_blank" rel="noopener"&gt;Add Table from Hosted Service to Another and Creat... - Esri Community&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Here's my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcgis
agol= arcgis.GIS("home")

search= agol.content.search('title: Mamalahoa 2021 (PMIS 217667) Field Data','Feature Layer')
flc= search[0]

for tbl in flc.tables:
  #Get the table's feature class it's supposed to match
  #You should probably preface this with an .endswith("__ATTACH") if you have other tables
	lay = tbl.properties.name.split("__")[0]
	for lyr in flc.layers:
		if lyr.properties.name == lay: #check to see if the attachment table matches something
			print(f"{lyr.properties.name}, {tbl.properties.name}")
			#Set up the relationships
            lyr_rel_dict = {
				"name": "Layer_to_Table",
				"relatedTableId": int(tbl.properties.id),
				"cardinality": "esriRelCardinalityOneToMany",
				"role": "esriRelRoleOrigin",
				"keyField": "GlobalID",
				"composite": True
			}
				
			tbl_rel_dict = {
				"name": "Table_to_Layer",
				"relatedTableId": int(lyr.properties.id),
				"cardinality": "esriRelCardinalityOneToMany",
				"role": "esriRelRoleDestination",
				"keyField": "REL_GLOBALID",
				"composite": True
			}
			# Add the relationships to both tables
			lyr.manager.add_to_definition({"relationships" : [lyr_rel_dict]})
			tbl.manager.add_to_definition({"relationships" : [tbl_rel_dict]})
			
			print(lyr.properties.relationships)
			
#double check
#get the information fresh, otherwise it won't appear
#and you'll run it again and have two relationships 
#per table/feature class pair
search= agol.content.search('title: Mamalahoa 2021 (PMIS 217667) Field Data','Feature Layer')
flc= search[0]
for lyr in flc.layers:
    print(f"{lyr.properties.name}, {lyr.properties.relationships}")
for tbl in flc.tables:
    print(f"{tbl.properties.name}, {tbl.properties.relationships}")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 22 Aug 2022 21:12:59 GMT</pubDate>
    <dc:creator>AlfredBaldenweck</dc:creator>
    <dc:date>2022-08-22T21:12:59Z</dc:date>
    <item>
      <title>Re-uploading feature classes with attachment tables</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/re-uploading-feature-classes-with-attachment/m-p/1195093#M57642</link>
      <description>&lt;P&gt;Hi all, I came across this issue and was wondering if anyone else had it.&lt;/P&gt;&lt;P&gt;On Pro 2.9:&lt;/P&gt;&lt;P&gt;I'm trying to consolidate some feature services. Since that isn't possible (Please vote for relevant ideas &lt;A href="https://community.esri.com/t5/arcgis-online-ideas/combine-hosted-feature-layers/idc-p/1194719" target="_blank" rel="noopener"&gt;here&lt;/A&gt; and &lt;A href="https://community.esri.com/t5/arcgis-online-ideas/add-new-feature-classes-to-hosted-feature-layers/idi-p/1163140/jump-to/first-unread-message" target="_blank" rel="noopener"&gt;here&lt;/A&gt;), I've resorted to downloading all of them to a local gdb and then republishing them as one service.&lt;/P&gt;&lt;P&gt;This normally works, but I found that if a feature class with an attachment table was included, the process would fail. Testing shows that it doesn't occur when publishing a feature class/attachment table that was created locally; it's specifically those that were previously hosted.&lt;/P&gt;&lt;P&gt;This behaviour occurs regardless of the original feature service, and regardless of the number of them included.&lt;/P&gt;&lt;P&gt;I deleted the relationship classes and everything worked; I was able to upload the feature classes and their attachment tables just fine.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Has anyone else had this problem? &lt;/STRONG&gt;If so, I'd like to log a bug report.&lt;/P&gt;&lt;P&gt;I was able to restore the relationships in the feature service.&amp;nbsp;&lt;BR /&gt;A large amount of this method was taken from&amp;nbsp;@ Clubdebambos's great blog post about combining feature services&amp;nbsp;&lt;A href="https://community.esri.com/t5/arcgis-api-for-python-blog/add-table-from-hosted-service-to-another-and/bc-p/1190303#M112" target="_blank" rel="noopener"&gt;Add Table from Hosted Service to Another and Creat... - Esri Community&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Here's my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcgis
agol= arcgis.GIS("home")

search= agol.content.search('title: Mamalahoa 2021 (PMIS 217667) Field Data','Feature Layer')
flc= search[0]

for tbl in flc.tables:
  #Get the table's feature class it's supposed to match
  #You should probably preface this with an .endswith("__ATTACH") if you have other tables
	lay = tbl.properties.name.split("__")[0]
	for lyr in flc.layers:
		if lyr.properties.name == lay: #check to see if the attachment table matches something
			print(f"{lyr.properties.name}, {tbl.properties.name}")
			#Set up the relationships
            lyr_rel_dict = {
				"name": "Layer_to_Table",
				"relatedTableId": int(tbl.properties.id),
				"cardinality": "esriRelCardinalityOneToMany",
				"role": "esriRelRoleOrigin",
				"keyField": "GlobalID",
				"composite": True
			}
				
			tbl_rel_dict = {
				"name": "Table_to_Layer",
				"relatedTableId": int(lyr.properties.id),
				"cardinality": "esriRelCardinalityOneToMany",
				"role": "esriRelRoleDestination",
				"keyField": "REL_GLOBALID",
				"composite": True
			}
			# Add the relationships to both tables
			lyr.manager.add_to_definition({"relationships" : [lyr_rel_dict]})
			tbl.manager.add_to_definition({"relationships" : [tbl_rel_dict]})
			
			print(lyr.properties.relationships)
			
#double check
#get the information fresh, otherwise it won't appear
#and you'll run it again and have two relationships 
#per table/feature class pair
search= agol.content.search('title: Mamalahoa 2021 (PMIS 217667) Field Data','Feature Layer')
flc= search[0]
for lyr in flc.layers:
    print(f"{lyr.properties.name}, {lyr.properties.relationships}")
for tbl in flc.tables:
    print(f"{tbl.properties.name}, {tbl.properties.relationships}")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2022 21:12:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/re-uploading-feature-classes-with-attachment/m-p/1195093#M57642</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2022-08-22T21:12:59Z</dc:date>
    </item>
  </channel>
</rss>

