Hello !
I've been trying to author a geoprocessing service that updates a field.
Below is a snippet of the Python Toolbox that I execute before publishing.
import arcpy
class Toolbox(object):
def __init__(self):
"""Define the toolbox (the name of the toolbox is the name of the
.pyt file)."""
self.label = "PythonToolbox"
self.alias = "mypythontoolbox"
# List of tool classes associated with this toolbox
self.tools = [PyToolUpdateFeatureField]
class PyToolUpdateFeatureField(object):
def __init__(self):
"""Define the tool (tool name is the name of the class)."""
self.label = "PyToolUpdateFeatureField"
self.description = ""
self.canRunInBackground = False
def getParameterInfo(self):
"""Define parameter definitions"""
param0 = arcpy.Parameter(
displayName="Input",
name="infeature",
#datatype="GPRecordSet",
#datatype="GPFeatureLayer",
#datatype="DEFeatureClass",
#datatype="GPLayer",
datatype="GPFeatureRecordSetLayer",
parameterType="Required",
direction="Input")
params = [param0]
return params
def isLicensed(self):
"""Set whether tool is licensed to execute."""
return True
def updateParameters(self, parameters):
"""Modify the values and properties of parameters before internal
validation is performed. This method is called whenever a parameter
has been changed."""
return
def updateMessages(self, parameters):
"""Modify the messages created by internal validation for each tool
parameter. This method is called after internal validation."""
return
def execute(self, parameters, messages):
"""The source code of the tool."""
fc = parameters[0].valueAsText
#fc = parameters[0].value
fields = ["OBJECTID", "Name"]
msg = "test"
#fcWorkspace = arcpy.Describe(fc).path
#edit = arcpy.da.Editor(fcWorkspace)
#edit.startEditing(False, False)
#edit.startOperation()
with arcpy.da.UpdateCursor(fc, fields) as cursor:
for row in cursor:
if row[0] == 1:
row[1] = msg
cursor.updateRow(row)
#edit.stopOperation()
#edit.stopEditing(True)
def postExecute(self, parameters):
"""This method takes place after outputs are processed and
added to the display."""
return
At publication stage the input I provide the tool with is a either a File GDB Feature class or a Enterprise GDB Feature class or a Feature Service layer.
Whatever the input is before publication, the published task only updates Feature Service layers. When trying to update a Feature class the task does not return any error but does not update the field either.
Are geoprocessing services only intended to work with published data ?
If not what am I missing out in authoring ?