alex92190

Dual geoprocessor

Discussion created by alex92190 on Apr 29, 2014
Hi all,
I have successfully created a first script that  can allow the client to query a layer, turn it into a feature set, and allow the client to extract data to the extent they wish. Now I would like to allow the client to perform a second query. To do so,  I need to run a second Extract data GP tool along with the first one. I now have two GP tool running. Now, everything works fine, except the fact that my ouput zipped file only contains empty shapefiles, and that I get the following error:

TypeError {stack: "TypeError: Cannot set property 'display' of undefi???allback (http://js.arcgis.com/3.9/init.js:75:350)", message: "Cannot set property 'display' of undefined"}
 "TypeError: Cannot set property 'display' of undefined
    at Object.l.set (http://js.arcgis.com/3.9/init.js:136:409)
    at http://127.0.0.1/Clipandship/examples/index_Query2.html:217:22
    at d._successHandler (http://js.arcgis.com/3.9/init.js:500:240)
    at d._handler (http://js.arcgis.com/3.9/init.js:1391:359)
    at http://js.arcgis.com/3.9/init.js:174:23
    at Object.c.load (http://js.arcgis.com/3.9/init.js:1387:350)
    at http://js.arcgis.com/3.9/init.js:640:344
    at c (http://js.arcgis.com/3.9/init.js:74:221)
    at d (http://js.arcgis.com/3.9/init.js:74:10)
    at resolve.callback (http://js.arcgis.com/3.9/init.js:75:350)" init.js:205
l init.js:205
(anonymous function) init.js:205
h.filter init.js:226
k


Her is my code:

gp = new Geoprocessor("http://webgisdevint1/arcgis/rest/services/Alex_Try/SDE/GPServer/Model4");
         gp.setOutSpatialReference({
            wkid: 102100
         });
   
   gp2 = new Geoprocessor("http://webgisdevint1/arcgis/rest/services/Alex_Try/GPUnits/GPServer/Units");
         gp2.setOutSpatialReference({
            wkid: 102100
         });  

function executeQueryTask() {
    var clipLayers = [];
            if (registry.byId("layer1").get("checked")) {
               clipLayers.push("SRA");
            }
            if (registry.byId("layer2").get("checked")) {
               clipLayers.push("Burn");
            }
   if (clipLayers.length === 0) {
               alert("No layers to clip, please select a layer you would like to clip...");
               return;
            }
          var county = document.getElementById("sel_county").value    
          var queryTask = new QueryTask("http://webgisdevint1/arcgis/rest/services/Alex_Try/AllLayers/MapServer/1");
          queryTask.on("complete", addToMap);
          var query = new Query();
          query.returnGeometry = true;
          query.outFields = ["*"];
          query.where = "FMNAME_UC = '" + county + "'";
          query.outSpatialReference = map.spatialReference;
          queryTask.execute(query, function(featureSet){
   var AOI = featureSet.features[0].geometry;
   
    var params = {
               "Layers_to_Clip": clipLayers,
               "Area_of_Interest": AOI,
               "Feature_Format": registry.byId("formatBox").get("value")
            };

            domStyle.set(loading, "display", "inline-block");
            gp.submitJob(params, completeCallback, statusCallback, function (error) {
               alert(error);
               domStyle.set(loading, "display", "none");
            });
         });
   
   }
   
   function executeQueryTask1() {
    var clipLayers = [];
            if (registry.byId("layer1").get("checked")) {
               clipLayers.push("SRA");
            }
            if (registry.byId("layer2").get("checked")) {
               clipLayers.push("Burn");
            }
   if (clipLayers.length === 0) {
               alert("No layers to clip, please select a layer you would like to clip...");
               return;
            }
    var unit = document.getElementById("unit_Sel").value    
          var queryTask = new QueryTask("http://webgisdevint1/arcgis/rest/services/Alex_Try/AllLayers/MapServer/0");
          queryTask.on("complete", addToMap2);
          var query = new Query();
          query.returnGeometry = true;
          query.outFields = ["*"];
          query.where = "UNITNAME = '" + unit + "'";
          query.outSpatialReference = map.spatialReference;
          queryTask.execute(query, function(featureSet){
   var AOI = featureSet.features[0].geometry;
   
    var params = {
               "Layers_to_Clip": clipLayers,
               "Area_of_Interest": AOI,
               "Feature_Format": registry.byId("formatBox").get("value")
            };

            domStyle.set(loading, "display", "inline-block");
            gp2.submitJob(params, completeCallbacknew, statusCallbacknew, function (error) {
               alert(error);
               domStyle.set(loading, "display", "none");
            });
         });
   
   }
  
         function completeCallback(jobInfo) {
            if (jobInfo.jobStatus !== "esriJobFailed") {
               gp.getResultData(jobInfo.jobId, "output34_zip", downloadFile);
            }
         }
   
   function completeCallbacknew(jobInfo) {
            if (jobInfo.jobStatus !== "esriJobFailed") {
               gp2.getResultData(jobInfo.jobId, "output34_zip", downloadFile);
            }
         }

         function statusCallback(jobInfo) {
          var status = jobInfo.jobStatus;
          if ( status === "esriJobFailed" ) {
            alert(status);
            domStyle.set("loading", "display", "none");
          }
          else if (status === "esriJobSucceeded"){
            domStyle.set("loading", "display", "none");
          }
        }
  function statusCallbacknew(jobInfo) {
          var status = jobInfo.jobStatus;
          if ( status === "esriJobFailed" ) {
            alert(status);
            domStyle.set("loading", "display", "none");
          }
          else if (status === "esriJobSucceeded"){
            domStyle.set("loading", "display", "none");
          }
        }
 
         function downloadFile(outputFile) {
            map.graphics.clear();
            var theurl = outputFile.value.url;
            window.location = theurl;
         }



Any idea how to reorganize the code so I can have the 2 geoprocessor work side by side fine?

Thank you

Outcomes