AnsweredAssumed Answered

Updating fields based on other fields - Python Script

Question asked by buehlerd on Sep 6, 2016
Latest reply on Sep 7, 2016 by buehlerd

My conundrum is, is it possible to calculate fields based on other fields in a stand-alone python script.  An example would be a group of values bases on two fields dictates what gets calculated in two other fields such as GeneralConcern = 1 (subytype) and SpecificConcern = "Pothole" and ContactDept IS NULL and DeptInfo IS NULL, calculate ContactDept = "Street Dept" and calculates DeptInfo = "715-555-5555".?


This is what I have come up with so far, but I am having a hard time wrapping my head around it.


import arcpy

# Set workspaces
workspace = r'C:\ESRITest\GeoReportingSystem\Testing9116\Testing9116.gdb'
outWorkspace = r'C:\ESRITest\GeoReportingSystem\Testing9116\Scratch.gdb'

# Set feature classes
tbl = r'C:\ESRITest\GeoReportingSystem\Testing9116\Testing9116.gdb\GeoReporting'

# Set other variables
pContact = "PrimaryContact"
contactInfo = "PrimaryInformation"
sql = """{} is NULL AND {} IS NULL""".format(pContact, contactInfo)

specificCon1 = ['Commercial Signage Concern','Temporary Signage Concern', 'Building Maintenance Issue','Fence Concern', 'Land Use Concern', 'Property Maintenance Concern', 'Setback or Property Concern', 'Other'] # Mulitple General Concern  Numbers
specificCon2 = ['Athletic Field Issue', 'Fairgrounds Issue', 'Park Maintenance Issue', 'Pool Issue', 'Restroom Issue', 'Shelter Issue', 'Skate Park Issue', 'Trail Maintenance Issue', 'Unsafe or Downed Tree', 'Zoo Issue', 'Other' ]

# Starting an Edit Session - DMB
edit = arcpy.da.Editor(workspace)
edit.startEditing(False, True)

# What I am trying to do is update the Null PrimaryContact and PrimaryInformation fields based on a General Concern (subtype number) and a specific concern.
#Example would be General Concern = 6 and Specific Concern = Pool Issue then PrimaryContact = Parks and Recreation and PrimaryInformation = 715-555-5555
# See specificCon1.  That variable will be a mix of several General Concern numbers like
with arcpy.da.UpdateCursor(tbl, ['PrimaryContact', 'PrimaryInformation'] , where_clause = sql) as cursor:
    for row in cursor:
        if value == specificCon1:
            row.setValue("PrimaryContact", "Development Services"
            row.setValue("PrimaryInformation", "715-555-5555")
        elif value == specificCon2:
            row.setValue("PrimaryContact", "Parks and Recreation"
            row.setValue("PrimaryInformation", "715-555-5555")
        else: == "??????":

# Closing the Edit Session - DMB