[GIS] Retrieving geoprocessing results in ArcGIS JavaScript API

arcgis-javascript-api

I'm executing a geoprocessing script in an ArcGIS JavaScript API map viewer, and it works until I attempt to read the job's output parameter.

My script:

function extractModel(results) {    
    var params = { "ModelName": ModelName }; // variable defined earlier

    // run geoprocessing service to export GDB, download results
    var gp = new Geoprocessor("http://myserver/arcgis/rest/services/Test4Custom/GPServer/Custom");
    gp.setUpdateDelay(5000); // check status every 5 seconds
    gp.submitJob(params, statusDone, statusCallback, errorBack);
}

function errorBack(jobInfo) {
    alert.window("Error encountered in geoprocessing script.")
    console.log("Status: " + gpStatus);
}
function statusCallback(jobInfo) {
    console.log("Status: " + gpStatus + " -- Continuing...");
}
function statusDone(jobInfo) {
    console.log("geoprocessing completed");
    console.log("Status: " + gpStatus);
    console.log("job id " + jobInfo.jobId);
    gp.getResultData(jobInfo.jobId, "Output_File", downloadResult, errorBack);
}

function downloadResult(result) {
    console.log("displaying result");
    console.log(result.value);
    console.log(result.dataType);
}

The geoprocessing task executes correctly, and the viewer script is running up until the gp.getResultData line. It's not getting into the downloadResult() function, and I'm getting this error in the console:

TypeError: c is not a function(…) "TypeError: c is not a function

Does this indicate a problem with my syntax in calling downloadResult(), or something else?

Note: The output parameter is indeed Output_File, and has a string in it when executed. Example:

{
 "paramName": "Output_File",
 "dataType": "GPString",
 "value": "c:\\arcgisserver\\directories\\arcgisjobs\\test4custom_gpserver\\je47fc8d361064c9e86237f397a873118\\scratch\\Data_SALLEY_20151215.gdb"
}

Best Answer

Here's a copy paste of a sample I use to get a file as output from a gp service to make it available for download. (It grabs text from a user and inserts it into a textfile, then returns the textfile. Its does a 'true' file output, not a string). I dont think its 100% what you want, but hopefully leads you down the right path...

javascript

 function submit() {  

      //reset messages      
      dojo.byId('downURL').innerHTML= "";

      //Go...
      var inputText = dojo.byId('inText').value;
      var params = {'Input_Text': inputText };
      console.log(params);
      gp_R.submitJob(params, gpJobComplete, gpJobStatus, function(error){
          alert(error);          
       });
    }   

    function gpJobComplete(jobInfo) {  

      if(jobInfo.jobStatus == "esriJobFailed") {                            
        dojo.byId('downURL').innerHTML = "Failed to generate text file";        
       }    
       else if (jobInfo.jobStatus == "esriJobSucceeded") {      
            gp_R.getResultData(jobInfo.jobId,"Output_Text_File", downloadFile);             
      }
    }       

    function downloadFile(outputFile) {  

       var theurl = outputFile.value.url;  
       dojo.byId('downURL').innerHTML = "<a href='"+ theurl + "'>Download File (right-click, save-as)</a>";  
    }

html body

<div id="downloadURLDiv">    
    <span id="downURL"></span>
  </div>