I know it has been a while, but the project scope has changed. I modified the code below. It works great if the data is not versioned, on the default version of the database, or in a file geodatabase. Is there a limitation when working with a version of a sde database? For instance, a webediting version of default.
# Orginal Code Created: 20/06/2014
# Orginal Copyright: (c) pschneider 2014
# Modified Code Created: December 08, 2014
# Modified Copyright: (c) DBuehler 2015
#-------------------------------------------------------------------------------
import arcpy # Libraries to import
# CSV writing function. Seperate function that is called int the main function
def log(txt, inFile, newRun):
try:
if newRun == True:
csvFile = open(inFile, 'w')
elif newRun == False:
csvFile = open(inFile, 'a')
csvFile.writelines(txt)
csvFile.flush()
csvFile.close()
except IOError:
print 'Unable to write to file ' + inFile
#Main function that creates a field array of fields, then writes the headers, and then rights matching rows and updates them
def main():
inDS = r"C:\TEMP\JUNK\Testing.gdb\Testing"
whereClause = r"STATUS = 'New' AND (PUBLICSTREETS = 'Damaged/Missing Street Sign' OR PUBLICSTREETS = 'Icy Intersection/Road' OR PUBLICSTREETS = 'Pothole' OR PUBLICSTREETS = 'Public Vegetation Concern')"
statusField = "STATUS"
logDir = r"C:\TEMP\JUNK\StreetDeptStreetIssues.csv"
updateTo = "Assigned"
fieldArr = []
for fld in arcpy.ListFields(inDS):
fieldArr.append(fld.name)
fieldArr.remove('SHAPE')
fieldArr.remove('GlobalID')
fieldArr.remove('REQUESTID')
fieldArr.remove('SOCIALLOGIN')
# Part where the headers get written to the log directory
headerLine = ""
for i in range(len(fieldArr)):
if i != len(fieldArr) - 1:
headerLine += str(fieldArr) + ","
else:
headerLine += str(fieldArr) + "\n"
log(headerLine, logDir, True)
fieldxi = fieldArr.index(statusField)
try:
with arcpy.da.UpdateCursor(inDS, fieldArr, whereClause) as cursor:
for row in cursor:
rowLine = ""
fileWrite = ""
for i in range(len(row)):
if i == whereClause:
logDir = cursor[row]
if i != len(row) - 1:
rowLine += str(row) + ","
else:
rowLine += str(row) + "\n"
row[fieldxi] = updateTo
cursor.updateRow(row)
log(rowLine, logDir, False)
except:
print 'Error updating the dataset'
if __name__ == '__main__':
main()