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"
}
3 Answers 3
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>
-
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– Erica2015年12月29日 19:24:28 +00:00Commented Dec 29, 2015 at 19:24 -
1See the comment that John posted on your original question, pretty sure thats the issue: You've declared
var gp = new Geoprocessor
inside a function andgp
doesnt exist outside of itKHibma– KHibma2015年12月29日 20:09:37 +00:00Commented 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 :DErica– Erica2015年12月29日 20:14:12 +00:00Commented 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– Lucas2020年03月10日 20:16:26 +00:00Commented 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– KHibma2020年03月11日 00:14:08 +00:00Commented Mar 11, 2020 at 0:14
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);
}
-
This doesn't change the error (it's still claiming
TypeError: c is not a function(...)
)Erica– Erica2015年12月29日 19:26:41 +00:00Commented Dec 29, 2015 at 19:26
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();
}
value
is a path or just"helloworld"
. (Eventually, no, it'll be an actual path.)gp
is defined