I have published the following script tool (which is wrapped in a model, i.e. just the script tool and all of its parameters) to ArcGIS Server 10. The GP service succeeds when run, but I cannot determine how to access the final output of the GP service. The result is a RecordSet object, and I can view it in the arcgisjobs/job-id/ directory when viewing it on the server.

However, I cannot figure out how to access the result via the REST API. As you can see, the script tool doesn't have an output parameter. When viewing the GP service via the REST Directory there are only the two inputs. I have tried using SetParameterAsText and a Result object and adding an output parameter to both the ST and the model but without any success. So, the question is how do I modify the script and/or script tool/model properties to designate an output parameter so that it can be accessed via the REST API and subsequently consumed in a web application?

I have read through this related question but it has not helped.

The REST Endpoint: http://atlas.utc.edu/ArcGIS/rest/services/RRI/DE/GPServer/Decision%20Engine

The Python script:

#Import ArcPy site package module
import arcpy
from arcpy import env
from arcpy import Extent
from arcpy import Raster
from arcpy import RecordSet
from arcpy.sa import ZonalStatisticsAsTable
from time import gmtime, strftime

# Check out ArcGIS Spatial Analyst extension license
# Set Environment Workspace
ws = env.workspace = WORKSPACE PATH

# Set Environment Raster Cell Size
cellSize = env.cellSize = 10
# Set Environment Processing Extent
processingExtent = Extent(602560.330672585, 3827530.65305605, 746490.330672585, 3966810.65305605)

environProcessingExtent = env.extent = processingExtent

# Strings representing rasters in the workspace
rasters = arcpy.GetParameterAsText(0).split(";")
# The dataset that defines the zones 
inZoneData = arcpy.GetParameterAsText(1)

# Determine Zone Dataset
if inZoneData == "Block Group":
    zoneField = "Value"
    zoneData = ws + "\\ToolData\\Data.gdb\\BG_Ras"
elif inZoneData == "Census Tract":
    zoneField = "TRACTCE10"
    zoneData = "\\ToolData\\Data.gdb\\CT_Ras" 
    zoneField = ""

addedRaster = Raster(ws + "\\ToolData\\Data.gdb\\constantRaster")

# Process each raster string
for raster in rasters:
    addedRaster = addedRaster + Raster(ws + "\\ToolData\\Data.gdb\\" + raster)

# Execute Zonal Statistics
zonalTable = RecordSet(ZonalStatisticsAsTable(zoneData, zoneField, addedRaster, "%SCRATCHWORKSPACE%\\zontalTable", "DATA", "MAXIMUM")).save("%SCRATCHWORKSPACE%\\rszt")

Some relevant images?

The Toolbox

Script Tool Parameters

Script Tool Parameters

Model Tool Parameters

Model Tool Parameters


  • Comments? Questions? Anything? Jan 11, 2012 at 20:38
  • Do you need the output as a record set? I'm wondering if it might help to add an extract or feature copy on the end of your model to get an output of gdb or shape file?
    – Steve
    Jan 12, 2012 at 0:40
  • Yes the intended output is a RecordSet, as it will be exposed as an output parameter of a geoprocessing task on ArcGIS server which can be consumed via the REST API. I get the output on the server itself, i.e. I can run the GP task and it puts the output recordset of the script in a unique job folder. The issue is that my script tool/model as it is currently constructed does not allow me to access the output via the REST API. See the link I posed to the REST endpoint, and there are only two input parameters but not an output parameter. When I run it, I cannot consume the result. Jan 12, 2012 at 2:10
  • Have you tried adding a return to your py script to return either the RecordSet or the path to the RecordSet?
    – Steve
    Jan 12, 2012 at 12:06
  • What features did you enable when you published? I'm not sure, but might Data Access be required in order to access the RecordSet?
    – Steve
    Jan 12, 2012 at 13:33

1 Answer 1


This worked for me:

  1. Set an output parameter of type RecordSet on the Script Tool and republish.
  2. Push your zonalStats into an in_memory/table. Or, if you need to write them out for whatever reason, copy the rows into an in_memory/table after you're done with the sa.
  3. SetOutputParameter in arcpy to be the Recordset.

    import arcpy
    arcpy.SetParameter(0, arcpy.RecordSet(foo))
    ##Note that this also works
    #r = arcpy.CreateObject("RecordSet")
    #arcpy.SetParameter(0, r)

Your url to the resource is going to follow this pattern:

There might also be trouble with your virtual directory mapping to your arcgisserver/arcgisjobs directory.

  • This accomplished the first part of getting the output parameter; I'm running into some server issues so I'll let you know if it works or not, award you the bounty. Thanks! Jan 12, 2012 at 22:13
  • Yeah, I've been down this road before so if you get stuck feel free to comment further. Jan 12, 2012 at 22:30
  • Where do we set the [nameOfOutputParameter]? I have now=arcpy.SetParameter(0,r). Thanks.
    – Justin
    Mar 9, 2012 at 18:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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