<?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: Python Relate New Table Records in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-relate-new-table-records/m-p/554076#M43305</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&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;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Brad&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 13 Aug 2019 16:46:35 GMT</pubDate>
    <dc:creator>BradOleson</dc:creator>
    <dc:date>2019-08-13T16:46:35Z</dc:date>
    <item>
      <title>Python Relate New Table Records</title>
      <link>https://community.esri.com/t5/python-questions/python-relate-new-table-records/m-p/554075#M43304</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;/P&gt;&lt;OL&gt;&lt;LI&gt;The user performs an edit on the polygon&lt;/LI&gt;&lt;LI&gt;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;/LI&gt;&lt;/OL&gt;&lt;P&gt;I have written a Python script that automates the record creation tasks. It works as follows:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;User edits one or more polygons&lt;/LI&gt;&lt;LI&gt;User runs the script&lt;/LI&gt;&lt;LI&gt;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;/LI&gt;&lt;/OL&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;&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;&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;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Aug 2019 15:55:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-relate-new-table-records/m-p/554075#M43304</guid>
      <dc:creator>BradOleson</dc:creator>
      <dc:date>2019-08-13T15:55:58Z</dc:date>
    </item>
    <item>
      <title>Re: Python Relate New Table Records</title>
      <link>https://community.esri.com/t5/python-questions/python-relate-new-table-records/m-p/554076#M43305</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&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;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Brad&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Aug 2019 16:46:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-relate-new-table-records/m-p/554076#M43305</guid>
      <dc:creator>BradOleson</dc:creator>
      <dc:date>2019-08-13T16:46:35Z</dc:date>
    </item>
    <item>
      <title>Re: Python Relate New Table Records</title>
      <link>https://community.esri.com/t5/python-questions/python-relate-new-table-records/m-p/554077#M43306</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can you just use Editor Tacking?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="http://desktop.arcgis.com/en/arcmap/10.6/manage-data/editing-fundamentals/enabling-editor-tracking.htm" title="http://desktop.arcgis.com/en/arcmap/10.6/manage-data/editing-fundamentals/enabling-editor-tracking.htm"&gt;Enabling and managing editor tracking—Help | ArcGIS Desktop&lt;/A&gt;&amp;nbsp; ('classic desktop')&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="https://pro.arcgis.com/en/pro-app/tool-reference/data-management/enable-editor-tracking.htm" title="https://pro.arcgis.com/en/pro-app/tool-reference/data-management/enable-editor-tracking.htm"&gt;Enable Editor Tracking—Data Management toolbox | ArcGIS Desktop&lt;/A&gt;&amp;nbsp; (pro)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Aug 2019 16:56:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-relate-new-table-records/m-p/554077#M43306</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2019-08-13T16:56:36Z</dc:date>
    </item>
  </channel>
</rss>

