I have a point feature with a single field used as the the attribute key for relationship classes to other tables. I am looking to automatically create a row into the related tables with the key field populated from the point creation. Any ideas how to auto populate the tables with that key?
Below is a screenshot of the inside of database.
Thank for the reply.
Yes that is what I would like to do.
When a user places a new point I would like them to be able to edit the related tables immediately without having to create a new record for that point. The related tables would automatically receive the point ID field that relates them together.
Ok, so I wrote a small python script that should work. The script should be able to handle a few points really quickly, but will be slower than needed if your very large numbers of input points. Since your said it will only be one at a time, this should be fine.
I included two ways of selected your related tables (manually and automatically). Remove the method you choose not to use. You will also need to make sure your key field already exists in all your related tables.
#Manually select related tables:
#Automatically select related tables:
relatedTables=arcpy.ListTables("MCCOG_Complaint.DBO.complaint*") #all table that begin with 'MCCOG_Complaint.DBO.complaint'
#Copy rows to related tables:
with arcpy.da.SearchCursor(workDir+"\\"+pointsFC,[keyField]) as inRows:
for inRow in inRows:
for relatedTable in relatedTables:
with arcpy.da.InsertCursor(workDir+"\\"+relatedTable,[keyField]) as outRows:
Let me know how it goes!
Seems like you would want to create the search cursor on just the selected features instead of everything in the point feature class. I think the way you have it now would copy all rows in the point feature class to the related tables each time a new point was added (creating duplicate records in the related tables).
I actually ran my python script outside of ArcMap using IDLE, but it can also be run within ArcMap. I did not set it up as a python add-in. Also, as Blake pointed out, the script will copy over ALL keys in the complaint file to the related tables each time it runs (thanks for that catch Blake!).
I have a few ideas on how to proceed;
Let me know what you think!
Option 3 sounds great. What I would like to do is get this script into a button that after the point is placed and assigned the key number then they could hit the button and apply to the related tables.
did you ever find a way to do this? I am trying to create the exact same thing with a button my end users could click to create the related records. Thanks for any pointers