<?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 Need help with editing value in versioned sde. Using arcpy.da.Editor in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/need-help-with-editing-value-in-versioned-sde/m-p/740661#M57274</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a python script that updates the tiles for a cached basemap using a feature class of polygons for the area of interest. Once the tiles are updated, I would like to update the values in the original feature class, changing the field "Cache" values from yes to no. I have no trouble with updating the tiles based on the feature class. I am having trouble changing the values in the feature class "Cache" field from yes to no.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The feature class is in SDE and is versioned. I am using cursors and da.Editor. ArcGIS 10.1.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I get this error: Objects in this class cannot be updated outside an edit session [GisWork.SDEADM.SectionsToCache]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;With this code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; edit = arcpy.da.Editor(env.workspace) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; edit.startEditing(True, True) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; edit.startOperation() &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Use an update cursor to update the values. This cursor gets all the records in the SectionsToCache feature class where CACHE = 'Yes' &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.UpdateCursor(inputFeatureClass, fieldName, whereClause) as cursor: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Update the field value to 'No'&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 cursor: &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; print row[0] &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[0]= "No" &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; cursor.updateRow(row) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; edit.stopOperation() &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; edit.stopEditing(True)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have tried placing the start and stop operations inside the for loop. I have tried with startEditing(False, True). I tried using with for the editor since this is supposed to eliminate the need to handle the stop and start, I believe, but had the same error.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have also tried to use CalculateField but the values did not update in the feature class. Since I need to use a Feature Layer, I am not sure if MakeFeatureLayer affects the input feature class. It looks like it did not. I can post my code for this but am more interested in getting this to work using the editor and cursors on the feature class itself.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Does anyone else have this working?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for any suggestions!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Janice.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 05 Sep 2013 20:20:06 GMT</pubDate>
    <dc:creator>JaniceBaird</dc:creator>
    <dc:date>2013-09-05T20:20:06Z</dc:date>
    <item>
      <title>Need help with editing value in versioned sde. Using arcpy.da.Editor</title>
      <link>https://community.esri.com/t5/python-questions/need-help-with-editing-value-in-versioned-sde/m-p/740661#M57274</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a python script that updates the tiles for a cached basemap using a feature class of polygons for the area of interest. Once the tiles are updated, I would like to update the values in the original feature class, changing the field "Cache" values from yes to no. I have no trouble with updating the tiles based on the feature class. I am having trouble changing the values in the feature class "Cache" field from yes to no.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The feature class is in SDE and is versioned. I am using cursors and da.Editor. ArcGIS 10.1.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I get this error: Objects in this class cannot be updated outside an edit session [GisWork.SDEADM.SectionsToCache]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;With this code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; edit = arcpy.da.Editor(env.workspace) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; edit.startEditing(True, True) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; edit.startOperation() &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Use an update cursor to update the values. This cursor gets all the records in the SectionsToCache feature class where CACHE = 'Yes' &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.UpdateCursor(inputFeatureClass, fieldName, whereClause) as cursor: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Update the field value to 'No'&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 cursor: &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; print row[0] &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[0]= "No" &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; cursor.updateRow(row) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; edit.stopOperation() &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; edit.stopEditing(True)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have tried placing the start and stop operations inside the for loop. I have tried with startEditing(False, True). I tried using with for the editor since this is supposed to eliminate the need to handle the stop and start, I believe, but had the same error.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have also tried to use CalculateField but the values did not update in the feature class. Since I need to use a Feature Layer, I am not sure if MakeFeatureLayer affects the input feature class. It looks like it did not. I can post my code for this but am more interested in getting this to work using the editor and cursors on the feature class itself.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Does anyone else have this working?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for any suggestions!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Janice.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Sep 2013 20:20:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/need-help-with-editing-value-in-versioned-sde/m-p/740661#M57274</guid>
      <dc:creator>JaniceBaird</dc:creator>
      <dc:date>2013-09-05T20:20:06Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with editing value in versioned sde. Using arcpy.da.Editor</title>
      <link>https://community.esri.com/t5/python-questions/need-help-with-editing-value-in-versioned-sde/m-p/740662#M57275</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;There is nothing like a weekend to give a person a fresh perspective! I got this working with the help from this thread: &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://forums.arcgis.com/threads/88714-Trying-to-edit-a-layer-in-a-versioned-SDE-GDB-in-a-Python-stand-alone-script" rel="nofollow" target="_blank"&gt;Trying-to-edit-a-layer-in-a-versioned-SDE-GDB-in-a-Python-stand-alone-script&lt;/A&gt;&lt;SPAN&gt; and correcting a couple of errors.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For one: I had the wrong workspace.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The next: I don't know that I can call this an error because I was using the documentation for CalculateField and passing in a VB string as the new value. This did not work. When I changed to using Python 9.3, it worked. Go figure!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is the final bit of code that is working:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outTable = "SectionsToUpdate" &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management(inputFeatureClass, outTable, whereClause, workspace) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.Editor(workspace) as edit: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(outTable, fieldName, "'No'", "PYTHON_9.3")&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Janice.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Sep 2013 16:07:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/need-help-with-editing-value-in-versioned-sde/m-p/740662#M57275</guid>
      <dc:creator>JaniceBaird</dc:creator>
      <dc:date>2013-09-09T16:07:39Z</dc:date>
    </item>
  </channel>
</rss>

