AnsweredAssumed Answered

Creating a layer in Geoprocessing Service causes an error

Question asked by nilsbabel on Jul 30, 2013
Latest reply on Oct 22, 2015 by jon.morris
I have some logic in my Geoprocessing service that creates a layer in order to add it to a map.

1.        mxd = arcpy.mapping.MapDocument(map_document)
2.        df = arcpy.mapping.ListDataFrames(mxd)[0]
3., "layer") #out_zone is an in_memory fc
4.        buffer_layer = arcpy.mapping.Layer("layer") #this doesn't work in the gp service
5.        arcpy.mapping.AddLayer(df, buffer_layer, "TOP")

This works just fine in the script tool from ArcMap.  It publishes successfully as well.  But when I run the GP service I get an error on line 4 above.  I have some traceback error reporting and it says the line that is failing is:

buffer_layer = arcpy.mapping.Layer(g_Esri_variable_3)

The error I get is Object: CreateObject layer invalid data source

So my question is what is g_Esri_variable_3?  What is ArcGIS Server doing differently than the desktop script tool?  Any suggestions on fixing this?