4

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"
}
6
  • 1
    Something is fishy with your output. Its a string, but its a path, but its a file. In terms of GP, you're showing it is indeed a String Is that really what you want, a string, which happens to be a path to a gdb (which is not a single file, but to windows a directory of 'stuff') returned to the user?
    – KHibma
    Commented Dec 15, 2015 at 15:07
  • For the purposes of testing the script, yes. Behavior is the same whether value is a path or just "helloworld". (Eventually, no, it'll be an actual path.)
    – Erica
    Commented Dec 15, 2015 at 15:08
  • 3
    i think your problem is that 'gp' itself is out of scope at that point, because you declared the variable inside a different function. Commented Dec 16, 2015 at 22:45
  • 1
    Further to John's comment, take a look @ developers.arcgis.com/javascript/jssamples/gp_viewshed.html in regards to how and where gp is defined
    – KHibma
    Commented Dec 29, 2015 at 20:11
  • Oh that was indeed the problem!!! @JohnGravois If you'd like to repost your comment as an answer, please do so I can accept it :)
    – Erica
    Commented Dec 29, 2015 at 20:12

3 Answers 3

5

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> 
6
  • Sorry for the delay (I was off work for a week and couldn't test) -- but this is still leading to the same TypeError: c is not a function(…) unfortunately :(
    – Erica
    Commented Dec 29, 2015 at 19:24
  • 1
    See the comment that John posted on your original question, pretty sure thats the issue: You've declared var gp = new Geoprocessor inside a function and gp doesnt exist outside of it
    – KHibma
    Commented Dec 29, 2015 at 20:09
  • This is what happens when I don't work on a project for ten days, I miss the comment that fixed my problem. Thank you so much for your advice and help :D
    – Erica
    Commented Dec 29, 2015 at 20:14
  • @KHibma Is outputFile.value.url the response for GPDataFile? My rest returns only value and when I set the output parameter as GPString, it returns the filepath of ArcGIS output instead a url. When I set as GPDataFile, the response appears as GPString yet and the value as "".
    – Lucas
    Commented Mar 10, 2020 at 20:16
  • @Lucas Is the actual output type in your REST endpoint a file, or string? Is your service sync or async? The code above is for async.
    – KHibma
    Commented Mar 11, 2020 at 0:14
2

I would put the function downloadResult inside statusDone.

function statusDone(jobInfo) {
    var downloadResult = function(result) {
       console.log("displaying result");
       console.log(result.value);
       console.log(result.dataType);
    }
    console.log("geoprocessing completed");
    console.log("Status: " + gpStatus);
    console.log("job id " + jobInfo.jobId);
    gp.getResultData(jobInfo.jobId, "Output_File", downloadResult, errorBack);
}
1
  • This doesn't change the error (it's still claiming TypeError: c is not a function(…))
    – Erica
    Commented Dec 29, 2015 at 19:26
0

If I am not wrong, your "Output_File" is having "esriGPParameterDirectionOutput" as direction in your GP service. And you want to retrieve value as per your job status. I was also getting the same error, but I found out the way. You can do one thing. Please refer https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest or https://www.w3schools.com/js/js_ajax_http.asp for XMLHttpRequest().

function statusDone(jobInfo) {
    gp.getResultData(jobInfo.jobId, "Output_File", downloadResult, errorBack);
    var xhr = new XMLHttpRequest();
    xhr.open("GET", "http://myserver/arcgis/rest/services/Test4Custom/GPServer/Custom/jobs/"+jobInfo.jobId+"/results/Output_File?f=pjson", true);
    xhr.withCredentials = true; (if you are GP service is secured else no need to write it)
        xhr.onreadystatechange = function() {
            if(xhr.readyState == 4 && xhr.status == 200) {
                var result = JSON.parse(xhr.responseText);
                alert(result.value);
            }
        };
        xhr.send();
}

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.