[GIS] ESRI geoprocessing service with Javascript API 3.5

arcgis-javascript-apiarcgis-servergeoprocessingjavascript

I am having issues getting a geoprocessing service to run. The service is a simple Python script that converts a table to CSV file. It runs fine in ArcMap. I can publish the service with the input as a constant and get it to run from Javascript. The problem is when I try to run the service with Feature Set created from a Feature Layer in Javascript. I can not get this to work!

My geoprocessing service is here.

function exportAll(){
    var query = new esri.tasks.Query();
    query.where = "1 = 1";
    query.outFields = ["*"];
    //parcelsFS is my Feature Service Layer
    parcelsFS.queryFeatures(query, function (features) {
    var inputFeatures = new esri.tasks.FeatureSet();
    inputFeatures = features.features;
    var params= { "Table_Name":inputFeatures};  
    gpTask.submitJob(params, completeCallback , statusCallback,function(error){
      //alert(error);
      //esri.hide(loading);
        });
    });
}

function completeCallback(jobInfo){
    if(jobInfo.jobStatus !== "esriJobFailed"){
      gpTask.getResultData(jobInfo.jobId,"Output_CSV", downloadFile);
    }
  }
  function statusCallback(jobInfo) {
    var status = jobInfo.jobStatus;
    if(status === "esriJobFailed"){
      alert(status);
      //esri.hide(loading);
    }
    else if (status === "esriJobSucceeded"){
      //esri.hide(loading);
    }
  }
  function downloadFile(outputFile){
    map.graphics.clear();
    var theurl = outputFile.value.url; 
        console.log(theurl);        
    window.location = theurl;
  }

Best Answer

What are the properties of features.features when you do this?

inputFeatures = features.features;

I'm pretty sure that your input features have to have a field list that matches the expected fields that you see when you inspect the 'submitJob' operation of your GP service.

For example, you have:

var inputFeatures = new esri.tasks.FeatureSet();
inputFeatures = features.features;
var params= { "Table_Name":inputFeatures};

I've run into a similar problem, and I add another line like so:

inputFeatures.fields = gpInputFields;

To make this:

var inputFeatures = new esri.tasks.FeatureSet();
inputFeatures = features.features;
inputFeatures.fields = gpInputFields;
var params= { "Table_Name":inputFeatures};

...where gpInputFields in your case would be this:

var gpInputFields = [{
    "name": "OBJECTID",
    "type": "esriFieldTypeOID",
    "alias": "OBJECTID"
},
{
    "name": "OID_1",
    "type": "esriFieldTypeInteger",
    "alias": "OID"
},
{
    "name": "Phase",
    "type": "esriFieldTypeString",
    "alias": "Phase",
    "length": 254
},
{
  "name": "Block",
  "type": "esriFieldTypeDouble",
  "alias": "Block"
},
{
  "name": "Street_Num",
  "type": "esriFieldTypeDouble",
  "alias": "Street_Num"
},
{
  "name": "Street_Nam",
  "type": "esriFieldTypeString",
  "alias": "Street_Nam",
  "length": 254
},
{
  "name": "Plan_Num",
  "type": "esriFieldTypeString",
  "alias": "Plan_Num",
  "length": 254
},
{
  "name": "Elevation",
  "type": "esriFieldTypeString",
  "alias": "Elevation",
  "length": 254
},
{
  "name": "Int_Select",
  "type": "esriFieldTypeString",
  "alias": "Int_Select",
  "length": 254
},
{
  "name": "Release",
  "type": "esriFieldTypeString",
  "alias": "Release",
  "length": 254
},
{
  "name": "IN_SCHEDULE",
  "type": "esriFieldTypeString",
  "alias": "IN_SCHEDULE",
  "length": 10
},
{
  "name": "OFFER_STATUS",
  "type": "esriFieldTypeString",
  "alias": "OFFER_STATUS",
  "length": 50
},
{
  "name": "BUYERS_NAME",
  "type": "esriFieldTypeString",
  "alias": "BUYERS_NAME",
  "length": 50
},
{
  "name": "ESCROW_DATE",
  "type": "esriFieldTypeDate",
  "alias": "ESCROW_DATE",
  "length": 36
},
{
  "name": "Parcel",
  "type": "esriFieldTypeString",
  "alias": "Parcel",
  "length": 254
},
{
  "name": "Street",
  "type": "esriFieldTypeString",
  "alias": "Street",
  "length": 50
},

..snip

{
  "name": "ESTIMATED_CLOSING_TEXT",
  "type": "esriFieldTypeString",
  "alias": "ESTIMATED_CLOSING_TEXT",
  "length": 50
},
{
  "name": "Shape_Length",
  "type": "esriFieldTypeDouble",
  "alias": "Shape_Length"
},
{
  "name": "Shape_Area",
  "type": "esriFieldTypeDouble",
  "alias": "Shape_Area"
}];

I copied/pasted that list from the first textfield here: http://arcgis-tamarackags101-235134627.us-west-2.elb.amazonaws.com/arcgis/rest/services/Emerson/TableToCSV_FS3/GPServer/TableToCSV/submitJob

That's but one of many, many problems that can arise with consuming GP Services from the JavaScript API. It's helpful while in development to turn in info messages for your service so it reports errors or status back to the console while the service is running.

Here's a link on how to do that: http://resources.arcgis.com/en/help/main/10.1/index.html#//005700000080000000

You can use Chrome debugging tools to view the response from the task as it is executing. Post the GP messages here if you keep having trouble.