Select to view content in your preferred language

arcpy.ListFields not working on feature service layer

472
1
11-01-2022 01:27 PM
YinghongLi1
Occasional Contributor

I use arcpy.ListFields to get editable fields.  It worked ok with the feature class from SDE.  Now I switched to use feature service on the portal and it gave out error like below:

Traceback (most recent call last):
  File "C:\Users\LiY\Application\A_Production\Desktop\AGProPythonTest\PythonArcPyCode\CalculateLineLength.py", line 49, in <module>
    flds = [fld.name for fld in arcpy.ListFields(line_lyr.name) if fld.editable]
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\__init__.py", line 1166, in ListFields
    return gp.listFields(dataset, wild_card, field_type)
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 354, in listFields
    self._gp.ListFields(*gp_fixargs(args, True)))
OSError: "DrainagePipe" does not exist

DrainagePipe is the layer name.  The code is this:

flds = [fld.name for fld in arcpy.ListFields(line_lyr.name) if fld.editable]

I read the help document and it does not say anything about not working on feature service.  

Please help.

0 Kudos
1 Reply
DonMorrison1
Occasional Contributor III

Perhaps it doesn't work on a layer?  Try to run it against the layer's datasource. Something like this:

flds = [fld.name for fld in arcpy.ListFields(line_lyr.dataSource) if fld.editable]