[GIS] Truncate Table tool with geoprocessing service

arcgis-10.1arcgis-servergeoprocessing-service

A model I built with ModelBuilder works as expected in Desktop yet generates numerous error messages when published as a geoprocessing (GP) service in ArcGIS Server 10.1 SP1. I've decided to start simple then and am trying to get just a single tool to work.

Here is my model. It has one parameter, a table or a feature class to truncate. When running in ArcGIS Desktop 10.1 SP1, user can specify what object should be truncated. When publishing as a model after getting a successful result, I use default settings for all settings (and Info for Message Level).

Truncate Table model

When running the GP service task in the same ArcGIS Desktop, I get this window in order to supply an object for truncating.

enter image description here

After pointing to a dataset (stored in a 10.1 file geodatabase on a local disk drive), the GP task gets running. The task does not truncate table and produces an error:
000187 : Only supports Geodatabase tables and feature classes.

My guess is that it has something to do with the Input mode of the task (User defined value) which makes it impossible to supply to my task a feature class from a file geodatabase in the file system. It seems as model uses the empty FeatureSet object instead of a feature class I supply when running the GP service task.

Is there a way to make the Truncate Table GP tool to use another feature class (not the same used when running the model first in Desktop before publishing) when published as a GP service?

The model for truncating a table works fine when there are no parameters exposed and when running the GP task of a published service, it runs over the same feature class I've used when running the model first to generate a result.

So, the GP service does work with feature classes yet only with the same one used when running the model before publishing.

Is it possible to supply a feature class to a GP task that differs from the feature class used to run the model and generate the result?

NB: the feature class is not copied to the arcgisserver folder, it is being processed properly right in the geodatabase on the disk, so this part works properly.

Best Answer

The problem was that the GP service is not able to use Feature Classes directly as input parameters. The solution to this is to use a parsing technique which would take a string from a user (name of the feature class) and then append this string variable to the full path of the feature class (I specify the geodatabase name forehand in the code).

It seemed as this is much easier to implement in Python rather than in ModelBuilder, so I've implemented this logic by using arcpy module in ArcGIS 10.1:

import arcpy
from arcpy import env
#Setting the env workspace to be an SDE geodatabase
#
env.workspace = r'C:\sde_at_DB101.sde'

#Getting the existing polygon feature class as input parameter
#
GetExistingPolyFC = arcpy.GetParameterAsText(0)
GetPolyFC = GetExistingPolyFC

# Truncate a feature class if it exists
#
if arcpy.Exists(GetPolyFC):
   arcpy.AddMessage("Polygon feature class exists, start working...")
   arcpy.TruncateTable_management(r'C:\sde_at_DB_101.sde\%s' %GetPolyFC)
   arcpy.AddMessage("Truncating table is complete")

else:
   arcpy.AddMessage("Polygon feature class does not exist")

I've used this logic for other bits of my bigger model and it works just fine as a GP service now. I've decided to rewrite the whole model as a Python script from scratch and it was much easier to implement and it performs much faster too when running the GP task.