<?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 Preserve GlobalIDs with python truncate append in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/preserve-globalids-with-python-truncate-append/m-p/1310504#M68407</link>
    <description>&lt;P&gt;I have a script that I am trying to truncate and append features from one DB to another... DEV to TEST&lt;/P&gt;&lt;P&gt;The truncate and Append &lt;U&gt;works&lt;/U&gt; but I need to &lt;U&gt;preserve&lt;/U&gt; the GlobalIDs.&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;I read that this is what I need to define but the GlobalIDs on the out FC are different than the original ... Again these are in different DBs but same FC name&lt;/P&gt;&lt;P&gt;Note this is an Enterprise Geodatabase....&lt;/P&gt;&lt;P&gt;Any thoughts?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;# Set the preserveGlobalIds environment to True
arcpy.env.preserveGlobalIds = True&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;# --Import arcpy module--------------------------------------------------------------------------------------
import arcpy

layers_to_Modify = {
"Database Connections\\GIS_DEV@gis_data.sde\\GIS_DATA.AAAA": "Database Connections\\GIS_TEST@gis_data.sde\\GIS_DATA.AAAA"
}

# Set the preserveGlobalIds environment to True
arcpy.env.preserveGlobalIds = True

def truncateAppendData():
    print("Starting to Replace the data")
    for layer in layers_to_Modify.keys():
        fromRelationship = layer
        toRelationship = layers_to_Modify[layer]      
        try:      
            arcpy.TruncateTable_management(toRelationship)
            arcpy.Append_management(fromRelationship, toRelationship, "NO_TEST")
            print("-- append Successful...".format())
        except Exception:
            # Handle errors accordingly...this is generic
            tb = sys.exc_info()[2]
            tb_info = traceback.format_tb(tb)[0]
            # Python 3.x
            #pymsg = f'PYTHON ERRORS:\n\tTraceback info:\t{tb_info}\n\tError Info:\t{str(sys.exc_info()[1])}\n'
            #msgs = f'ArcPy ERRORS:\t{arcpy.GetMessages(2)}\n'
            # Python 2.7
            pymsg = 'PYTHON ERRORS:\n\tTraceback info:\t{tb_info}\n\tError Info:\t{str(sys.exc_info()[1])}\n'
            msgs = 'ArcPy ERRORS:\t{arcpy.GetMessages(2)}\n'
            print(pymsg)
            print(msgs)
            print.error("-- PYTHON ERRORS:\n\tTraceback info:\t{tb_info}\n\tError Info:\t{str(sys.exc_info()[1])}\n".format())
            print.error("-- ArcPy ERRORS:\t{arcpy.GetMessages(2)}\n".format())

if __name__ == '__main__':

    ## Truncate and Append Data
    truncateAppendData()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 21 Jul 2023 15:01:28 GMT</pubDate>
    <dc:creator>kapalczynski</dc:creator>
    <dc:date>2023-07-21T15:01:28Z</dc:date>
    <item>
      <title>Preserve GlobalIDs with python truncate append</title>
      <link>https://community.esri.com/t5/python-questions/preserve-globalids-with-python-truncate-append/m-p/1310504#M68407</link>
      <description>&lt;P&gt;I have a script that I am trying to truncate and append features from one DB to another... DEV to TEST&lt;/P&gt;&lt;P&gt;The truncate and Append &lt;U&gt;works&lt;/U&gt; but I need to &lt;U&gt;preserve&lt;/U&gt; the GlobalIDs.&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;I read that this is what I need to define but the GlobalIDs on the out FC are different than the original ... Again these are in different DBs but same FC name&lt;/P&gt;&lt;P&gt;Note this is an Enterprise Geodatabase....&lt;/P&gt;&lt;P&gt;Any thoughts?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;# Set the preserveGlobalIds environment to True
arcpy.env.preserveGlobalIds = True&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;# --Import arcpy module--------------------------------------------------------------------------------------
import arcpy

layers_to_Modify = {
"Database Connections\\GIS_DEV@gis_data.sde\\GIS_DATA.AAAA": "Database Connections\\GIS_TEST@gis_data.sde\\GIS_DATA.AAAA"
}

# Set the preserveGlobalIds environment to True
arcpy.env.preserveGlobalIds = True

def truncateAppendData():
    print("Starting to Replace the data")
    for layer in layers_to_Modify.keys():
        fromRelationship = layer
        toRelationship = layers_to_Modify[layer]      
        try:      
            arcpy.TruncateTable_management(toRelationship)
            arcpy.Append_management(fromRelationship, toRelationship, "NO_TEST")
            print("-- append Successful...".format())
        except Exception:
            # Handle errors accordingly...this is generic
            tb = sys.exc_info()[2]
            tb_info = traceback.format_tb(tb)[0]
            # Python 3.x
            #pymsg = f'PYTHON ERRORS:\n\tTraceback info:\t{tb_info}\n\tError Info:\t{str(sys.exc_info()[1])}\n'
            #msgs = f'ArcPy ERRORS:\t{arcpy.GetMessages(2)}\n'
            # Python 2.7
            pymsg = 'PYTHON ERRORS:\n\tTraceback info:\t{tb_info}\n\tError Info:\t{str(sys.exc_info()[1])}\n'
            msgs = 'ArcPy ERRORS:\t{arcpy.GetMessages(2)}\n'
            print(pymsg)
            print(msgs)
            print.error("-- PYTHON ERRORS:\n\tTraceback info:\t{tb_info}\n\tError Info:\t{str(sys.exc_info()[1])}\n".format())
            print.error("-- ArcPy ERRORS:\t{arcpy.GetMessages(2)}\n".format())

if __name__ == '__main__':

    ## Truncate and Append Data
    truncateAppendData()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jul 2023 15:01:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/preserve-globalids-with-python-truncate-append/m-p/1310504#M68407</guid>
      <dc:creator>kapalczynski</dc:creator>
      <dc:date>2023-07-21T15:01:28Z</dc:date>
    </item>
    <item>
      <title>Re: Preserve GlobalIDs with python truncate append</title>
      <link>https://community.esri.com/t5/python-questions/preserve-globalids-with-python-truncate-append/m-p/1310523#M68408</link>
      <description>&lt;P&gt;UGGGGGGG my mistake... I was looking at the wrong Feature Class in the Destination... duh.... That code is working fine....&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jul 2023 15:20:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/preserve-globalids-with-python-truncate-append/m-p/1310523#M68408</guid>
      <dc:creator>kapalczynski</dc:creator>
      <dc:date>2023-07-21T15:20:49Z</dc:date>
    </item>
    <item>
      <title>Re: Preserve GlobalIDs with python truncate append</title>
      <link>https://community.esri.com/t5/python-questions/preserve-globalids-with-python-truncate-append/m-p/1310524#M68409</link>
      <description>&lt;P&gt;Please REFER to the original post... that code works ....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jul 2023 15:21:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/preserve-globalids-with-python-truncate-append/m-p/1310524#M68409</guid>
      <dc:creator>kapalczynski</dc:creator>
      <dc:date>2023-07-21T15:21:32Z</dc:date>
    </item>
  </channel>
</rss>

