<?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 Feature class field update with Geoprocessing service in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/feature-class-field-update-with-geoprocessing/m-p/1292946#M26883</link>
    <description>&lt;P&gt;Hello !&lt;/P&gt;&lt;P&gt;I've been trying to author a geoprocessing service that updates a field.&lt;/P&gt;&lt;P&gt;Below is a snippet of the Python Toolbox that I execute before publishing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;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.&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;Are geoprocessing services only intended to work with published data ?&lt;BR /&gt;If not what am I missing out in authoring ?&lt;/P&gt;</description>
    <pubDate>Fri, 26 May 2023 08:03:10 GMT</pubDate>
    <dc:creator>OlivierLefevre</dc:creator>
    <dc:date>2023-05-26T08:03:10Z</dc:date>
    <item>
      <title>Feature class field update with Geoprocessing service</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/feature-class-field-update-with-geoprocessing/m-p/1292946#M26883</link>
      <description>&lt;P&gt;Hello !&lt;/P&gt;&lt;P&gt;I've been trying to author a geoprocessing service that updates a field.&lt;/P&gt;&lt;P&gt;Below is a snippet of the Python Toolbox that I execute before publishing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;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.&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;Are geoprocessing services only intended to work with published data ?&lt;BR /&gt;If not what am I missing out in authoring ?&lt;/P&gt;</description>
      <pubDate>Fri, 26 May 2023 08:03:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/feature-class-field-update-with-geoprocessing/m-p/1292946#M26883</guid>
      <dc:creator>OlivierLefevre</dc:creator>
      <dc:date>2023-05-26T08:03:10Z</dc:date>
    </item>
    <item>
      <title>Re: Feature class field update with Geoprocessing service</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/feature-class-field-update-with-geoprocessing/m-p/1292961#M26884</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Update the getParameterInfo method:&lt;/P&gt;&lt;P&gt;Change the datatype parameter for the infeature parameter from GPFeatureRecordSetLayer to Any. This will allow the parameter to accept various types of data.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Here's an updated version of the &lt;/SPAN&gt;getParameterInfo&lt;SPAN&gt; method:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;def getParameterInfo(self):&lt;BR /&gt;"""Define parameter definitions"""&lt;BR /&gt;param0 = arcpy.Parameter(&lt;BR /&gt;displayName="Input",&lt;BR /&gt;name="infeature",&lt;BR /&gt;datatype="Any",&lt;BR /&gt;parameterType="Required",&lt;BR /&gt;direction="Input")&lt;BR /&gt;# Uncomment and use the appropriate datatype for the input parameter&lt;BR /&gt;# param0.datatype = "GPFeatureLayer"&lt;BR /&gt;# param0.datatype = "DEFeatureClass"&lt;BR /&gt;# param0.datatype = "GPLayer"&lt;BR /&gt;params = [param0]&lt;BR /&gt;return params&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 25 May 2023 09:50:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/feature-class-field-update-with-geoprocessing/m-p/1292961#M26884</guid>
      <dc:creator>Jamesmillere</dc:creator>
      <dc:date>2023-05-25T09:50:08Z</dc:date>
    </item>
    <item>
      <title>Re: Feature class field update with Geoprocessing service</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/feature-class-field-update-with-geoprocessing/m-p/1293377#M26886</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/687252"&gt;@Jamesmillere&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your answer but the tool cannot run which such a parameter. It returns an error something in French like "Tool has failed to open : ValueError: ParameterObject: non valid input value for DataType property"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Maybe it's a matter of ArcGIS versions. Mine are ArcGIS Pro 2.9.6 and ArcGIS Server 10.9.1&lt;/P&gt;</description>
      <pubDate>Fri, 26 May 2023 07:56:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/feature-class-field-update-with-geoprocessing/m-p/1293377#M26886</guid>
      <dc:creator>OlivierLefevre</dc:creator>
      <dc:date>2023-05-26T07:56:42Z</dc:date>
    </item>
    <item>
      <title>Re: Feature class field update with Geoprocessing service</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/feature-class-field-update-with-geoprocessing/m-p/1293391#M26887</link>
      <description>&lt;P&gt;Adding a message to my code below, I noticed that any Feature Class (from GDB or SDE) used as task input is converted to an in memory feature set.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;    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
        messages.addMessage("Input :" + fc)
        messages.addMessage("Path :" + fcWorkspace)
        
        #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)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Messages are :&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;Input :in_memory\feature_set&lt;/P&gt;&lt;P class="lia-align-left lia-indent-padding-left-30px"&gt;Path :in_memory&lt;/P&gt;&lt;P class="lia-align-left lia-indent-padding-left-30px"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it possible to author a generic geoprocessing service that updates Feature Services as well as Feature Classes ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 May 2023 12:32:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/feature-class-field-update-with-geoprocessing/m-p/1293391#M26887</guid>
      <dc:creator>OlivierLefevre</dc:creator>
      <dc:date>2023-05-26T12:32:16Z</dc:date>
    </item>
  </channel>
</rss>

