<?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 Using Python to Update Relationship Table in Geodatabase Questions</title>
    <link>https://community.esri.com/t5/geodatabase-questions/using-python-to-update-relationship-table/m-p/797412#M2456</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a feature class that has a related table that tracks user edits. The manual way to perform the task is:&lt;BR /&gt;1.The user performs an edit on the polygon&lt;BR /&gt;2.The user adds a new record to the related table and updates attributes accordingly (type, edited by, edited date, etc.). This is done in the Attribute Editor window using the interface provided for adding a related record. The relationship is tracked via the polygon ID, which the user copies into the new related record.&lt;/P&gt;&lt;P&gt;I have written a Python script that automates the record creation tasks. It works as follows:&lt;BR /&gt;1.User edits one or more polygons&lt;BR /&gt;2.User runs the script&lt;BR /&gt;3.Script creates the new records in the edit table, enters the polygon ID and the script dialog provides the remaining update info for the script to fill in the other necessary fields&lt;/P&gt;&lt;P&gt;What I need to know is how, in Python, to update the relationship for the newly created records to relate them back to their respective poly using the poly ID. Currently, when the updated poly is selected and viewed the newly added record is not shown in the Attribute Editor dialog as a related record.&lt;/P&gt;&lt;P&gt;Can anyone provide to me where to go for the missing link? The usual Google search didn't really yield the secret to me when I started digging yesterday.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the code as it exists now:&lt;/P&gt;&lt;P&gt;**************************************&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;import arcpy, arcgisscripting, sys, os, time, datetime, getpass, shutil, smtplib&lt;BR /&gt;from arcpy import env&lt;BR /&gt;from time import strftime&lt;/P&gt;&lt;P&gt;mxd = arcpy.mapping.MapDocument("CURRENT")&lt;/P&gt;&lt;P&gt;# From dialog, get the table field default values. To set different defaults, use the&lt;BR /&gt;# parameters dialog inside ArcMap/toolbox interface.&lt;BR /&gt;structuresFC = arcpy.GetParameterAsText(0)&lt;BR /&gt;structureEditLogTable = arcpy.GetParameterAsText(1)&lt;BR /&gt;qcFlag = arcpy.GetParameterAsText(2)&lt;BR /&gt;userComments = arcpy.GetParameterAsText(3)&lt;BR /&gt;modifiedBy = arcpy.GetParameterAsText(4)&lt;BR /&gt;modifiedDate = arcpy.GetParameterAsText(5)&lt;BR /&gt;lastEditedUser = arcpy.GetParameterAsText(6)&lt;BR /&gt;lastEditedDate = arcpy.GetParameterAsText(7)&lt;BR /&gt;clearSelected = arcpy.GetParameterAsText(8)&lt;/P&gt;&lt;P&gt;# Determine query date&lt;BR /&gt;queryDate = datetime.datetime.strptime(lastEditedDate, '%m/%d/%Y').strftime('%Y-%m-%d')&lt;/P&gt;&lt;P&gt;# Determine if any edits have been performed on the Structure Edit Log today; if so, determine the latest time of the updates&lt;BR /&gt;timeQuery = "LAST_EDITED_USER = '" + lastEditedUser + "' and LAST_EDITED_DATE &amp;gt; timestamp '" + queryDate + " 00:00:00' and MODIFIED_BY = '" +&amp;nbsp; modifiedBy + "'"&lt;BR /&gt;arcpy.SelectLayerByAttribute_management(structureEditLogTable, "NEW_SELECTION", timeQuery)&lt;/P&gt;&lt;P&gt;# Determine if there is a selection; if there is, edits have been made today&lt;BR /&gt;describeTable = arcpy.Describe(structureEditLogTable)&lt;BR /&gt;if describeTable.FIDSet == '':&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; anyEdits = "No"&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; timestampList = []&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Set the timestamp for the list to Midnight today - no edits have taken place yet&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; timestampList.append("00:00:00")&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; queryTime = "00:00:00"&lt;BR /&gt;else:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Edits have been made, read the times of the selection set into a list&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldsSEL = ["LAST_EDITED_DATE"]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; timestampList = []&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.SearchCursor(structureEditLogTable, fieldsSEL) as srchCursor:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in srchCursor:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; timestamp = (row[0])&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; timestampList.append(timestamp)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; lastEditTime = max(timestampList)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; queryTime = (lastEditTime).strftime('%H:%M:%S')&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# Clear the selections to prep for next phase&lt;BR /&gt;arcpy.SelectLayerByAttribute_management(structuresFC, "CLEAR_SELECTION")&lt;BR /&gt;arcpy.SelectLayerByAttribute_management(structureEditLogTable, "CLEAR_SELECTION")&lt;/P&gt;&lt;P&gt;# Create select query based on current user being last edited user and edit time being greater than 00:00:00&lt;BR /&gt;selectionQuery = "LAST_EDITED_USER = '" + lastEditedUser + "' and LAST_EDITED_DATE &amp;gt; timestamp '" + queryDate + " " + queryTime + "'"&lt;/P&gt;&lt;P&gt;# Select records from the Structure Edit Log table that were edited by the user in this edit session&lt;BR /&gt;arcpy.SelectLayerByAttribute_management(structuresFC, "NEW_SELECTION", selectionQuery)&lt;BR /&gt;arcpy.RefreshActiveView()&lt;/P&gt;&lt;P&gt;# Describe the table state to determine if records are selected&lt;BR /&gt;describeTable = arcpy.Describe(structuresFC)&lt;/P&gt;&lt;P&gt;try:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Test to see that there is a selection set first. If not, message the user and exit.&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if describeTable.FIDSet == '':&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("No features are selected in the Structures Feature Class; exiting!")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Set the parameters for the selected features *only*&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldsFC = ["STRUCTUREID"]&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldsSEL = ["STRUCTUREID", "QC_FLAG", "COMMENTS", "MODIFIED_BY", "MODIFIED_DATE"]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; try:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Set up a cursor to get the current StructureID in the FC&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.SearchCursor(structuresFC, fieldsFC) as srchCursor:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in srchCursor:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; currentStructureID = row[0]&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.InsertCursor(structureEditLogTable, fieldsSEL) as insertCursor:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; insertCursor.insertRow((currentStructureID, "Y", userComments, modifiedBy, modifiedDate))&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del insertCursor&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del srchCursor, row&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; except RuntimeError as err:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # This will run if the user is not currently in an edit session&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if "cannot be updated outside an edit session" in err.message:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("Not currently in an edit session. Exit tool, start an edit session and rerun the tool!")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; raise err&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; selectionQuery = "LAST_EDITED_USER = '" + lastEditedUser + "' and LAST_EDITED_DATE &amp;gt; timestamp '" + queryDate + " 00:00:00' and EDIT_ID IS NULL"&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(structureEditLogTable, "NEW_SELECTION", selectionQuery)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshActiveView()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldsSEL = ["OBJECTID","EDIT_ID"]&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.UpdateCursor(structureEditLogTable, fieldsSEL) as updateCursor:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in updateCursor:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[1] = row[0]&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; updateCursor.updateRow(row)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del updateCursor, row&lt;/P&gt;&lt;P&gt;except Exception as e:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("Exception")&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddError(e.args[0])&lt;/P&gt;&lt;P&gt;if clearSelected == "true":&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Clear selection and refresh the map&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(structuresFC, "CLEAR_SELECTION")&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(structureEditLogTable, "CLEAR_SELECTION")&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshActiveView()&lt;BR /&gt;else:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshActiveView()&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;End code***********&lt;/P&gt;&lt;P&gt;I think I may have answered my own question, but here's my sanity check...in case anyone is reading or has read this:&lt;/P&gt;&lt;P&gt;I need to add the requisite records to the relationship table providing the structure ID and its new related Edit_ID. I'm assuming like any other table in SDE, there shouldn't be a problem doing this via the Insert cursor, probably in the next line of my code. I'll be giving this a try, but if anyone has any caveats to this I'd appreciate your input!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 13 Aug 2019 16:55:37 GMT</pubDate>
    <dc:creator>BradOleson</dc:creator>
    <dc:date>2019-08-13T16:55:37Z</dc:date>
    <item>
      <title>Using Python to Update Relationship Table</title>
      <link>https://community.esri.com/t5/geodatabase-questions/using-python-to-update-relationship-table/m-p/797412#M2456</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a feature class that has a related table that tracks user edits. The manual way to perform the task is:&lt;BR /&gt;1.The user performs an edit on the polygon&lt;BR /&gt;2.The user adds a new record to the related table and updates attributes accordingly (type, edited by, edited date, etc.). This is done in the Attribute Editor window using the interface provided for adding a related record. The relationship is tracked via the polygon ID, which the user copies into the new related record.&lt;/P&gt;&lt;P&gt;I have written a Python script that automates the record creation tasks. It works as follows:&lt;BR /&gt;1.User edits one or more polygons&lt;BR /&gt;2.User runs the script&lt;BR /&gt;3.Script creates the new records in the edit table, enters the polygon ID and the script dialog provides the remaining update info for the script to fill in the other necessary fields&lt;/P&gt;&lt;P&gt;What I need to know is how, in Python, to update the relationship for the newly created records to relate them back to their respective poly using the poly ID. Currently, when the updated poly is selected and viewed the newly added record is not shown in the Attribute Editor dialog as a related record.&lt;/P&gt;&lt;P&gt;Can anyone provide to me where to go for the missing link? The usual Google search didn't really yield the secret to me when I started digging yesterday.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the code as it exists now:&lt;/P&gt;&lt;P&gt;**************************************&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;import arcpy, arcgisscripting, sys, os, time, datetime, getpass, shutil, smtplib&lt;BR /&gt;from arcpy import env&lt;BR /&gt;from time import strftime&lt;/P&gt;&lt;P&gt;mxd = arcpy.mapping.MapDocument("CURRENT")&lt;/P&gt;&lt;P&gt;# From dialog, get the table field default values. To set different defaults, use the&lt;BR /&gt;# parameters dialog inside ArcMap/toolbox interface.&lt;BR /&gt;structuresFC = arcpy.GetParameterAsText(0)&lt;BR /&gt;structureEditLogTable = arcpy.GetParameterAsText(1)&lt;BR /&gt;qcFlag = arcpy.GetParameterAsText(2)&lt;BR /&gt;userComments = arcpy.GetParameterAsText(3)&lt;BR /&gt;modifiedBy = arcpy.GetParameterAsText(4)&lt;BR /&gt;modifiedDate = arcpy.GetParameterAsText(5)&lt;BR /&gt;lastEditedUser = arcpy.GetParameterAsText(6)&lt;BR /&gt;lastEditedDate = arcpy.GetParameterAsText(7)&lt;BR /&gt;clearSelected = arcpy.GetParameterAsText(8)&lt;/P&gt;&lt;P&gt;# Determine query date&lt;BR /&gt;queryDate = datetime.datetime.strptime(lastEditedDate, '%m/%d/%Y').strftime('%Y-%m-%d')&lt;/P&gt;&lt;P&gt;# Determine if any edits have been performed on the Structure Edit Log today; if so, determine the latest time of the updates&lt;BR /&gt;timeQuery = "LAST_EDITED_USER = '" + lastEditedUser + "' and LAST_EDITED_DATE &amp;gt; timestamp '" + queryDate + " 00:00:00' and MODIFIED_BY = '" +&amp;nbsp; modifiedBy + "'"&lt;BR /&gt;arcpy.SelectLayerByAttribute_management(structureEditLogTable, "NEW_SELECTION", timeQuery)&lt;/P&gt;&lt;P&gt;# Determine if there is a selection; if there is, edits have been made today&lt;BR /&gt;describeTable = arcpy.Describe(structureEditLogTable)&lt;BR /&gt;if describeTable.FIDSet == '':&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; anyEdits = "No"&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; timestampList = []&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Set the timestamp for the list to Midnight today - no edits have taken place yet&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; timestampList.append("00:00:00")&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; queryTime = "00:00:00"&lt;BR /&gt;else:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Edits have been made, read the times of the selection set into a list&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldsSEL = ["LAST_EDITED_DATE"]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; timestampList = []&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.SearchCursor(structureEditLogTable, fieldsSEL) as srchCursor:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in srchCursor:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; timestamp = (row[0])&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; timestampList.append(timestamp)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; lastEditTime = max(timestampList)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; queryTime = (lastEditTime).strftime('%H:%M:%S')&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# Clear the selections to prep for next phase&lt;BR /&gt;arcpy.SelectLayerByAttribute_management(structuresFC, "CLEAR_SELECTION")&lt;BR /&gt;arcpy.SelectLayerByAttribute_management(structureEditLogTable, "CLEAR_SELECTION")&lt;/P&gt;&lt;P&gt;# Create select query based on current user being last edited user and edit time being greater than 00:00:00&lt;BR /&gt;selectionQuery = "LAST_EDITED_USER = '" + lastEditedUser + "' and LAST_EDITED_DATE &amp;gt; timestamp '" + queryDate + " " + queryTime + "'"&lt;/P&gt;&lt;P&gt;# Select records from the Structure Edit Log table that were edited by the user in this edit session&lt;BR /&gt;arcpy.SelectLayerByAttribute_management(structuresFC, "NEW_SELECTION", selectionQuery)&lt;BR /&gt;arcpy.RefreshActiveView()&lt;/P&gt;&lt;P&gt;# Describe the table state to determine if records are selected&lt;BR /&gt;describeTable = arcpy.Describe(structuresFC)&lt;/P&gt;&lt;P&gt;try:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Test to see that there is a selection set first. If not, message the user and exit.&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if describeTable.FIDSet == '':&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("No features are selected in the Structures Feature Class; exiting!")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Set the parameters for the selected features *only*&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldsFC = ["STRUCTUREID"]&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldsSEL = ["STRUCTUREID", "QC_FLAG", "COMMENTS", "MODIFIED_BY", "MODIFIED_DATE"]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; try:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Set up a cursor to get the current StructureID in the FC&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.SearchCursor(structuresFC, fieldsFC) as srchCursor:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in srchCursor:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; currentStructureID = row[0]&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.InsertCursor(structureEditLogTable, fieldsSEL) as insertCursor:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; insertCursor.insertRow((currentStructureID, "Y", userComments, modifiedBy, modifiedDate))&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del insertCursor&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del srchCursor, row&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; except RuntimeError as err:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # This will run if the user is not currently in an edit session&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if "cannot be updated outside an edit session" in err.message:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("Not currently in an edit session. Exit tool, start an edit session and rerun the tool!")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; raise err&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; selectionQuery = "LAST_EDITED_USER = '" + lastEditedUser + "' and LAST_EDITED_DATE &amp;gt; timestamp '" + queryDate + " 00:00:00' and EDIT_ID IS NULL"&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(structureEditLogTable, "NEW_SELECTION", selectionQuery)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshActiveView()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldsSEL = ["OBJECTID","EDIT_ID"]&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.UpdateCursor(structureEditLogTable, fieldsSEL) as updateCursor:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in updateCursor:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[1] = row[0]&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; updateCursor.updateRow(row)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del updateCursor, row&lt;/P&gt;&lt;P&gt;except Exception as e:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("Exception")&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddError(e.args[0])&lt;/P&gt;&lt;P&gt;if clearSelected == "true":&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Clear selection and refresh the map&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(structuresFC, "CLEAR_SELECTION")&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(structureEditLogTable, "CLEAR_SELECTION")&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshActiveView()&lt;BR /&gt;else:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshActiveView()&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;End code***********&lt;/P&gt;&lt;P&gt;I think I may have answered my own question, but here's my sanity check...in case anyone is reading or has read this:&lt;/P&gt;&lt;P&gt;I need to add the requisite records to the relationship table providing the structure ID and its new related Edit_ID. I'm assuming like any other table in SDE, there shouldn't be a problem doing this via the Insert cursor, probably in the next line of my code. I'll be giving this a try, but if anyone has any caveats to this I'd appreciate your input!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Aug 2019 16:55:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/geodatabase-questions/using-python-to-update-relationship-table/m-p/797412#M2456</guid>
      <dc:creator>BradOleson</dc:creator>
      <dc:date>2019-08-13T16:55:37Z</dc:date>
    </item>
    <item>
      <title>Re: Using Python to Update Relationship Table</title>
      <link>https://community.esri.com/t5/geodatabase-questions/using-python-to-update-relationship-table/m-p/797413#M2457</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi &lt;A href="https://community.esri.com/migrated-users/7545"&gt;Brad Oleson&lt;/A&gt;‌,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just had a brief look at your code, and couldn't help but notice the following bit:&lt;/P&gt;&lt;P&gt;&lt;IMG class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/457081_pastedImage_3.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I know it sounds counter-intuitive, but keep the block of code for editing short; Try to plan the layout and looping structures – find out what information you need to collect at the start of the script,&amp;nbsp; add this information to dictionaries with custom classes instead of opening the cursor and then reading and performing operations on the values within the block. You should see some performance optimisation from this change.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, I would probably use a config file to store those column names.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Lastly, using "with" statement should&amp;nbsp;&lt;SPAN style="font-size: 11.0pt;"&gt;release the cursor from memory reliably; you shouldn't need to delete the cursor again.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt;"&gt;Hope that helps.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Aug 2019 04:21:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/geodatabase-questions/using-python-to-update-relationship-table/m-p/797413#M2457</guid>
      <dc:creator>DerrickWong</dc:creator>
      <dc:date>2019-08-15T04:21:18Z</dc:date>
    </item>
  </channel>
</rss>

