How to append data to a feature service with a related table?

3791
6
12-04-2019 06:46 AM
ChelseaTabor1
New Contributor III

I'm trying to append data to a feature service with a related table online, but I'm having trouble getting the appended data to relate to the related table.  I append the new data to the fs, then append the related records to the related table.  Any new data added (from survey123) appears as it should with its related records.  Is there a way to append new data with related records to an existing feature service and its related table?  I attached an image of the fs data if that helps.

0 Kudos
6 Replies
by Anonymous User
Not applicable

Hi Chelsea Tabor‌,

This is a common scenario because of the uniqueness of GlobalIDs. I recorded this video which goes through a workflow of how to address the issue, keeping parent features connected to their related records when appending: 

How To: Preserve GlobalID/GUID Relationships when Appending Records - YouTube 

Hope it helps,

-Peter 

WillHouston
New Contributor III

This is not working from a file geodatabase to an Arc Online feature layer using the Append tool:

Failed on input OID 3922, could not write value '{028C6C51-9C71-4D14-8E4C-0FA1B5B49A6F}' to output field match_fks

0 Kudos
by Anonymous User
Not applicable

Hi Will,

I'm revisiting this workflow tomorrow and will consider your scenario and error message. I'll post here if I can figure out what the issue might be. In the meantime have you reached out to Esri Support to take a look? 

Esri Support Contact Support 

Thanks,

-Peter

0 Kudos
WillHouston
New Contributor III

I posted another question to the community to see if anyone else has seen the issue. I did not reach out to support directly. Admittedly I never watched your full video, but I think what I had been doing was similar (copy the foreign key and primary keys to another GUID and then match them back up after the append).

I wasn't ever able to get the GUID type to work, but I was able to copy the primary and foreign keys to string and match them up with a basic script I had written before I knew about your tutorial:

import arcpy
import os

class CustomCancelException(Exception):
   pass


def my_function(post_layer, sign_layer):
edit_started = False

try:
   with arcpy.da.SearchCursor(post_layer, ["GLOBALID", "preserve_guid"]) as scur:
      key_map = {}
      for srow in scur:
         key_map[srow[1]] = srow[0]

with arcpy.da.UpdateCursor(sign_layer, ["parentfk", "preserve_guid"]) as ucur:
   for urow in ucur:
         new_fk = key_map.get(urow[1], None)
         urow[0] = new_fk
         ucur.updateRow(urow)

except CustomCancelException as err:
arcpy.AddError(err)
finally:

if __name__ == '__main__':
post_layer = arcpy.GetParameter(0)
sign_layer = arcpy.GetParameter(1)

my_function(post_layer, sign_layer)

The quotations aren't preserving indentation, but that's the general idea. I never tried copying from a string into a GUID because I thought that wouldn't work and I already had this script.

by Anonymous User
Not applicable

Hi Will, thanks for the reply and posting your solution here - I did look into this more and I'm not sure why copying to GUID was failing. But I'm sure the above script will assist someone else and is surely quicker than the manual process in my video. 

MichaelWallace3
New Contributor III

@Anonymous User thanks for the video this helped a bit. 

@WillHouston  thanks for the code, I can get everything to work except the actual editing of the table. really frustrating maybe I will modify to do select and calculate field. 

0 Kudos