wthughes

Published Python Script Error ?Syntax?

Discussion created by wthughes on Oct 22, 2013
Latest reply on Oct 23, 2013 by timmo1982
I created a simple python script which selects all polyons and then updates a field based on user input. The python script works fine in ArcMap, but fails when running the script as a geoprocessing rest service (10.1 Server). I think the problem must be the variable - zoneStatus. The values are input parameters in a value list - for example "Zone QCd" and "Not Validated".

I don't think this:
zoneStatus = ""'" + arcpy.GetParameterAsText(0) + "'""

is correct here:

row.setValue("ZONE_STATUS", zoneStatus)

# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# zoningUpdate.py
# Created on: 2013-10-22 11:52:45.00000
#   (generated by ArcGIS/ModelBuilder)
# Usage: zoningUpdate <Expression> 
# Description: 
# ---------------------------------------------------------------------------


# Import arcpy module
import arcpy


print "workspace"
arcpy.env.workspace = "c:/arcgisserver/connections/sdedbconn.sde"


# Script arguments
#Expression = "\"ZONE_NAME\" = " + "'" + arcpy.GetParameterAsText(0) + "'"
#if Expression == '#' or not Expression:
Expression = "\"ZONE_NAME\" LIKE 'ZONE%'" # provide a default value if unspecified
zoneStatus = ""'" + arcpy.GetParameterAsText(0) + "'""


# Process: Make Feature Layer
arcpy.MakeFeatureLayer_management("dur.zone_area", "zone_lyr", Expression, "", "OBJECTID OBJECTID VISIBLE NONE;ABDSECTOR ABDSECTOR VISIBLE NONE;BUFFER_DIST BUFFER_DIST VISIBLE NONE;CODE CODE VISIBLE NONE;FEAT_DESC FEAT_DESC VISIBLE NONE;INSTLN_ID INSTLN_ID VISIBLE NONE;NARRATIVE NARRATIVE VISIBLE NONE;ZONE_ID ZONE_ID VISIBLE NONE; ZONE_STATUS ZONE_STATUS VISIBLE NONE;ZONE_NAME ZONE_NAME VISIBLE NONE;SHAPE SHAPE VISIBLE NONE;SHAPE_Length SHAPE_Length VISIBLE NONE;SHAPE_Area SHAPE_Area VISIBLE NONE")


print "create update cursor"
# Create update cursor for feature class
rows = arcpy.UpdateCursor("zone_lyr")


# Update the field used in buffer so the distance is based on the
for row in rows:
    row.setValue("ZONE_STATUS", zoneStatus)
    rows.updateRow(row)
print "delete row and rows"
# Delete cursor and row objects to remove locks on the data
del row
del rows

Outcomes