I have created a Python Script Tool that returns a FeatureLayer using the following two lines of code:

arcpy.MakeFeatureLayer_management(scratch_fc, "GeocodedZIPsLayer")
arcpy.SetParameterAsText(1, "GeocodedZIPsLayer")

This works as expected in ArcMap, and resulting POINT features are added to the map without an issues. When I publish this as a Geoprocessing Service, the service fails, and I see the following error in the server logs:

Invalid return value: GeocodedZIPsLayer

What is the best practice for returning a FeatureLayer through a REST service?

  • 2
    Have you tried just using arcpy.SetParameter() rather than returning it as text? – crmackey Dec 15 '15 at 2:34
  • 1
    Try using copyfeatures instead of makefeaturelayer and just set the output to in_memory if that's your requirement – KHibma Dec 15 '15 at 4:13
  • If I use CopyFeatures_management(), how do I return those features as an output parameter? What would I put in as the argument to arcpy.SetParameter(1,????)? – George Dec 15 '15 at 16:17
  • Also, the same error is returned when I use arcpy.SetParameter(1, "GeocodedZIPsLayer") – George Dec 15 '15 at 16:29

Expanding on my comment - use CopyFeatures instead of MakeFeatureLayer

import arcpy
import os

# processing and analysis here...
myOutput = os.path.join(arcpy.env.scratchGDB, "output")
# ..or myOutput = "in_memory/output"
arcpy.CopyFeatures_management(myInput, myOutput)

# use the output variable...
arcpy.SetParameterAsText(1, myOutput)
# ...or use the actual output
#  arcpy.SetParameterAsText(1,  os.path.join(arcpy.env.scratchGDB, "output"))
| improve this answer | |
  • This solved the initial error, so I'll mark it as the solution. Now debugging why my layer is empty... – George Dec 16 '15 at 19:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.